Skip to content

Commit

Permalink
graph.c: register a callback for graph output
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bo Yang authored and Junio C Hamano committed Jun 1, 2010
1 parent 2efcc97 commit b5a4de9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b5a4de9

Please sign in to comment.