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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
---
 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]