git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 5/6] Register a callback for graph output

From
Bo Yang <struggleyb.nku@gmail.com>
Date
May 26, 2010, 07:23 UTC
Message-ID
<1274858637-13243-3-git-send-email-struggleyb.nku@gmail.com>
In-Reply-To
<1274858637-13243-2-git-send-email-struggleyb.nku@gmail.com>

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>
---
 graph.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/graph.c b/graph.c
index e6bbcaa..ac7c605 100644
--- 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;
 }
 
-- 
1.6.0.4
Previous: Bo YangNext: Bo Yang
Message 3 of 7 in “diff.c: Output the text graph padding before each diff line”
  1. 3/6 diff.c: Output the text graph padding before each diff lineBo Yang, May 26, 2010
  2. 4/6 Emit a whole line once a timeBo Yang, May 26, 2010
  3. 5/6 Register a callback for graph outputBo Yang, May 26, 2010
  4. 6/6 Make --color-words work well with --graphBo Yang, May 26, 2010
  5. Junio C HamanoMay 29, 2010
  6. Junio C HamanoMay 29, 2010
  7. Bo YangMay 29, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.