summaryrefslogtreecommitdiff
path: root/graph.c
diff options
context:
space:
mode:
authorJames Coglan <jcoglan@gmail.com>2019-10-15 23:47:48 +0000
committerJunio C Hamano <gitster@pobox.com>2019-10-16 11:11:24 +0900
commit210179a20d585f6a96e0963db69790e590bd9433 (patch)
tree1beb3ed2ca8e062a7cc0425c481599e27a691e82 /graph.c
parentfbccf255f9449c2f617d875ebf78b9f1730fae5d (diff)
downloadgit-210179a20d585f6a96e0963db69790e590bd9433.tar.gz
graph: handle line padding in `graph_next_line()`
Now that the display width of graph lines is implicitly tracked via the `graph_line` interface, the calls to `graph_pad_horizontally()` no longer need to be located inside the individual output functions, where the character counting was previously being done. All the functions called by `graph_next_line()` generate a line of output, then call `graph_pad_horizontally()`, and finally change the graph state if necessary. As padding is the final change to the output done by all these functions, it can be removed from all of them and done in `graph_next_line()` instead. I've also moved the guard in `graph_output_padding_line()` that checks the graph has a commit; this function is only called by `graph_next_line()` and we must not pad the `graph_line` if no commit is set. Signed-off-by: James Coglan <jcoglan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'graph.c')
-rw-r--r--graph.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/graph.c b/graph.c
index 2f81a5d23d..4c68557b17 100644
--- a/graph.c
+++ b/graph.c
@@ -733,24 +733,12 @@ static void graph_output_padding_line(struct git_graph *graph,
int i;
/*
- * We could conceivable be called with a NULL commit
- * if our caller has a bug, and invokes graph_next_line()
- * immediately after graph_init(), without first calling
- * graph_update(). Return without outputting anything in this
- * case.
- */
- if (!graph->commit)
- return;
-
- /*
* Output a padding row, that leaves all branch lines unchanged
*/
for (i = 0; i < graph->num_new_columns; i++) {
graph_line_write_column(line, &graph->new_columns[i], '|');
graph_line_addch(line, ' ');
}
-
- graph_pad_horizontally(graph, line);
}
@@ -767,7 +755,6 @@ static void graph_output_skip_line(struct git_graph *graph, struct graph_line *l
* of the graph is missing.
*/
graph_line_addstr(line, "...");
- graph_pad_horizontally(graph, line);
if (graph->num_parents >= 3 &&
graph->commit_index < (graph->num_columns - 1))
@@ -832,8 +819,6 @@ static void graph_output_pre_commit_line(struct git_graph *graph,
graph_line_addch(line, ' ');
}
- graph_pad_horizontally(graph, line);
-
/*
* Increment graph->expansion_row,
* and move to state GRAPH_COMMIT if necessary
@@ -967,8 +952,6 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
graph_line_addch(line, ' ');
}
- graph_pad_horizontally(graph, line);
-
/*
* Update graph->state
*/
@@ -1043,8 +1026,6 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
}
}
- graph_pad_horizontally(graph, line);
-
/*
* Update graph->state
*/
@@ -1186,8 +1167,6 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
}
}
- graph_pad_horizontally(graph, line);
-
/*
* Swap mapping and new_mapping
*/
@@ -1204,31 +1183,43 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
int graph_next_line(struct git_graph *graph, struct strbuf *sb)
{
+ int shown_commit_line = 0;
struct graph_line line = { .buf = sb, .width = 0 };
+ /*
+ * We could conceivable be called with a NULL commit
+ * if our caller has a bug, and invokes graph_next_line()
+ * immediately after graph_init(), without first calling
+ * graph_update(). Return without outputting anything in this
+ * case.
+ */
+ if (!graph->commit)
+ return -1;
+
switch (graph->state) {
case GRAPH_PADDING:
graph_output_padding_line(graph, &line);
- return 0;
+ break;
case GRAPH_SKIP:
graph_output_skip_line(graph, &line);
- return 0;
+ break;
case GRAPH_PRE_COMMIT:
graph_output_pre_commit_line(graph, &line);
- return 0;
+ break;
case GRAPH_COMMIT:
graph_output_commit_line(graph, &line);
- return 1;
+ shown_commit_line = 1;
+ break;
case GRAPH_POST_MERGE:
graph_output_post_merge_line(graph, &line);
- return 0;
+ break;
case GRAPH_COLLAPSING:
graph_output_collapsing_line(graph, &line);
- return 0;
+ break;
}
- assert(0);
- return 0;
+ graph_pad_horizontally(graph, &line);
+ return shown_commit_line;
}
static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)