]> asedeno.scripts.mit.edu Git - git.git/commitdiff
graph.c: register a callback for graph output
authorBo Yang <struggleyb.nku@gmail.com>
Wed, 26 May 2010 07:23:56 +0000 (15:23 +0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Jun 2010 01:02:07 +0000 (18:02 -0700)
It will look better if the 'git log --graph' print
the graph pading lines before the diff output just
like what it does for commit message.
And this patch leverage the new diff prefix callback
function to achieve this.

Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
graph.c

diff --git a/graph.c b/graph.c
index e6bbcaa8c4655add3ecaca578e948355795e36ca..ac7c60540645761d3c99fb405a69cb2d06aaddc2 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -211,6 +211,18 @@ struct git_graph {
        unsigned short default_column_color;
 };
 
+static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void *data)
+{
+       struct git_graph *graph = data;
+       static struct strbuf msgbuf = STRBUF_INIT;
+
+       assert(graph);
+
+       strbuf_reset(&msgbuf);
+       graph_padding_line(graph, &msgbuf);
+       return &msgbuf;
+}
+
 struct git_graph *graph_init(struct rev_info *opt)
 {
        struct git_graph *graph = xmalloc(sizeof(struct git_graph));
@@ -244,6 +256,13 @@ struct git_graph *graph_init(struct rev_info *opt)
        graph->mapping = xmalloc(sizeof(int) * 2 * graph->column_capacity);
        graph->new_mapping = xmalloc(sizeof(int) * 2 * graph->column_capacity);
 
+       /*
+        * The diff output prefix callback, with this we can make
+        * all the diff output to align with the graph lines.
+        */
+       opt->diffopt.output_prefix = diff_output_prefix_callback;
+       opt->diffopt.output_prefix_data = graph;
+
        return graph;
 }