Skip to content

Commit b5a4de9

Browse files
byanggitster
authored andcommitted
graph.c: register a callback for graph output
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2efcc97 commit b5a4de9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

graph.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ struct git_graph {
211211
unsigned short default_column_color;
212212
};
213213

214+
static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void *data)
215+
{
216+
struct git_graph *graph = data;
217+
static struct strbuf msgbuf = STRBUF_INIT;
218+
219+
assert(graph);
220+
221+
strbuf_reset(&msgbuf);
222+
graph_padding_line(graph, &msgbuf);
223+
return &msgbuf;
224+
}
225+
214226
struct git_graph *graph_init(struct rev_info *opt)
215227
{
216228
struct git_graph *graph = xmalloc(sizeof(struct git_graph));
@@ -244,6 +256,13 @@ struct git_graph *graph_init(struct rev_info *opt)
244256
graph->mapping = xmalloc(sizeof(int) * 2 * graph->column_capacity);
245257
graph->new_mapping = xmalloc(sizeof(int) * 2 * graph->column_capacity);
246258

259+
/*
260+
* The diff output prefix callback, with this we can make
261+
* all the diff output to align with the graph lines.
262+
*/
263+
opt->diffopt.output_prefix = diff_output_prefix_callback;
264+
opt->diffopt.output_prefix_data = graph;
265+
247266
return graph;
248267
}
249268

0 commit comments

Comments
 (0)