Skip to content

Commit 7ef9de3

Browse files
committed
graph: helper functions for printing commit header
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 mostly work (see the next commit for some oddness). Signed-off-by: Jeff King <[email protected]>
1 parent 34abe70 commit 7ef9de3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

graph.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ int graph_is_commit_finished(struct git_graph const *graph)
13951395
return (graph->state == GRAPH_PADDING);
13961396
}
13971397

1398-
void graph_show_commit(struct git_graph *graph)
1398+
static void graph_show_commit_1(struct git_graph *graph, int only_pre)
13991399
{
14001400
struct strbuf msgbuf = STRBUF_INIT;
14011401
int shown_commit_line = 0;
@@ -1416,6 +1416,8 @@ void graph_show_commit(struct git_graph *graph)
14161416
}
14171417

14181418
while (!shown_commit_line && !graph_is_commit_finished(graph)) {
1419+
if (only_pre && graph->state == GRAPH_COMMIT)
1420+
break;
14191421
shown_commit_line = graph_next_line(graph, &msgbuf);
14201422
fwrite(msgbuf.buf, sizeof(char), msgbuf.len,
14211423
graph->revs->diffopt.file);
@@ -1429,6 +1431,16 @@ void graph_show_commit(struct git_graph *graph)
14291431
strbuf_release(&msgbuf);
14301432
}
14311433

1434+
void graph_show_precommit(struct git_graph *graph)
1435+
{
1436+
graph_show_commit_1(graph, 1);
1437+
}
1438+
1439+
void graph_show_commit(struct git_graph *graph)
1440+
{
1441+
graph_show_commit_1(graph, 0);
1442+
}
1443+
14321444
void graph_show_oneline(struct git_graph *graph)
14331445
{
14341446
struct strbuf msgbuf = STRBUF_INIT;

graph.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ int graph_width(struct git_graph *graph);
218218
*/
219219
void graph_show_commit(struct git_graph *graph);
220220

221+
/*
222+
* Same as graph_show_commit, but stop just _before_ printing
223+
* the actual commit line.
224+
*/
225+
void graph_show_precommit(struct git_graph *graph);
226+
221227
/*
222228
* If the graph is non-NULL, print one line of the history graph to stdout.
223229
* Does not print a terminating newline on the last line.

0 commit comments

Comments
 (0)