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

[PATCH 4/5] graph: helper functions for printing commit header

From
Jeff King <peff@peff.net>
Date
Sep 29, 2016, 08:38 UTC
Message-ID
<20160929083815.xgbdv62srna3cbg5@sigill.intra.peff.net>
In-Reply-To
<20160929083315.vwb3aurwbyjwlkjn@sigill.intra.peff.net>

The idea here is to make it possible to print something right _before_ a commit in the graph. It's a bit ugly, but it seems to work.

Signed-off-by: Jeff King <peff@peff.net>
---
 graph.c | 14 +++++++++++++-
 graph.h |  6 ++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/graph.c b/graph.c
index d4e8519..56daa70 100644
--- a/graph.c
+++ b/graph.c
@@ -1218,7 +1218,7 @@ int graph_is_commit_finished(struct git_graph const *graph)
 	return (graph->state == GRAPH_PADDING);
 }
 
-void graph_show_commit(struct git_graph *graph)
+static void graph_show_commit_1(struct git_graph *graph, int only_pre)
 {
 	struct strbuf msgbuf = STRBUF_INIT;
 	int shown_commit_line = 0;
@@ -1239,6 +1239,8 @@ void graph_show_commit(struct git_graph *graph)
 	}
 
 	while (!shown_commit_line && !graph_is_commit_finished(graph)) {
+		if (only_pre && graph->state == GRAPH_COMMIT)
+			break;
 		shown_commit_line = graph_next_line(graph, &msgbuf);
 		fwrite(msgbuf.buf, sizeof(char), msgbuf.len,
 			graph->revs->diffopt.file);
@@ -1252,6 +1254,16 @@ void graph_show_commit(struct git_graph *graph)
 	strbuf_release(&msgbuf);
 }
 
+void graph_show_precommit(struct git_graph *graph)
+{
+	graph_show_commit_1(graph, 1);
+}
+
+void graph_show_commit(struct git_graph *graph)
+{
+	graph_show_commit_1(graph, 0);
+}
+
 void graph_show_oneline(struct git_graph *graph)
 {
 	struct strbuf msgbuf = STRBUF_INIT;
diff --git a/graph.h b/graph.h
index af62339..e13e97f 100644
--- a/graph.h
+++ b/graph.h
@@ -97,6 +97,12 @@ int graph_width(struct git_graph *graph);
  */
 void graph_show_commit(struct git_graph *graph);
 
+/*
+ * Same as graph_show_commit, but stop just _before_ printing
+ * the actual commit line.
+ */
+void graph_show_precommit(struct git_graph *graph);
+
 /*
  * If the graph is non-NULL, print one line of the history graph to stdout.
  * Does not print a terminating newline on the last line.
-- 
2.10.0.566.g5365f87
Previous: Jeff KingNext: Jeff King
Message 9 of 20 in “git log --oneline alternative with dates, times and initials”
  1. git log --oneline alternative with dates, times and initialsKyle J. McKay, Sep 29, 2016
  2. Jeff KingSep 29, 2016
  3. 1/5 pretty: allow formatting DATE_SHORTJeff King, Sep 29, 2016
  4. Jacob KellerSep 30, 2016
  5. SZEDER GáborSep 30, 2016
  6. Jacob KellerSep 30, 2016
  7. Jeff KingOct 1, 2016
  8. 3/5 graph: fix extra spaces in graph_padding_lineJeff King, Sep 29, 2016
  9. 4/5 graph: helper functions for printing commit headerJeff King, Sep 29, 2016
  10. 2/5 pretty: allow formatting names as initialsJeff King, Sep 29, 2016
  11. Junio C HamanoSep 29, 2016
  12. Jeff KingSep 29, 2016
  13. 5/5 log: add --commit-header optionJeff King, Sep 29, 2016
  14. Junio C HamanoSep 29, 2016
  15. Jeff KingSep 29, 2016
  16. Kyle J. McKaySep 29, 2016
  17. Jeff KingSep 29, 2016
  18. Junio C HamanoSep 29, 2016
  19. Jeff KingSep 29, 2016
  20. Junio C HamanoSep 29, 2016

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.