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 <struggleyb.nku@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Bo Yang committed
May 26, 2010 at 15:23 UTC
b5a4de9d506030fce1b70a06dc49090a46877c3f
1 file changed
+19
graph.c
+19
@@ -211,6 +211,18 @@ struct git_graph {
211
unsigned short default_column_color;
212
};
213
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
+
226
struct git_graph *graph_init(struct rev_info *opt)
227
{
228
struct git_graph *graph = xmalloc(sizeof(struct git_graph));
@@ -244,6 +256,13 @@ struct git_graph *graph_init(struct rev_info *opt)
256
graph->mapping = xmalloc(sizeof(int) * 2 * graph->column_capacity);
257
graph->new_mapping = xmalloc(sizeof(int) * 2 * graph->column_capacity);
258
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
+
266
return graph;
267
}
268