@matheusbsbs / matheus-bagliano / commits / f1979d6b3f
Fork 0

graph API: avoid printing unnecessary padding before some octopus merges

When an octopus merge is printed, several lines are printed before it to move over existing branch lines to its right. This is needed to make room for the children of the octopus merge. For example: | | | | | | \ \ | | \ \ | | \ \ | M---. \ \ | |\ \ \ \ \ However, this step isn't necessary if there are no branch lines to the right of the octopus merge. Therefore, skip this step when it is not needed, to avoid printing extra lines that don't really serve any purpose. Signed-off-by: Adam Simpkins <adam@adamsimpkins.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Adam Simpkins committed Jun 1, 2008 at 13:56 UTC f1979d6b3fba41fb6ca92290bf8e10d58ede8970
1 file changed +8 -5
graph.c
+8 -5
@@ -450,16 +450,18 @@ void graph_update(struct git_graph *graph, struct commit *commit)
450 * it never finished its output. Goto GRAPH_SKIP, to print out
451 * a line to indicate that portion of the graph is missing.
452 *
453 - * Otherwise, if there are 3 or more parents, we need to print
454 - * extra rows before the commit, to expand the branch lines around
455 - * it and make room for it.
453 + * If there are 3 or more parents, we may need to print extra rows
454 + * before the commit, to expand the branch lines around it and make
455 + * room for it. We need to do this only if there is a branch row
456 + * (or more) to the right of this commit.
457 *
458 * If there are less than 3 parents, we can immediately print the
459 * commit line.
460 */
461 if (graph->state != GRAPH_PADDING)
462 graph->state = GRAPH_SKIP;
462 - else if (graph->num_parents >= 3)
463 + else if (graph->num_parents >= 3 &&
464 + graph->commit_index < (graph->num_columns - 1))
465 graph->state = GRAPH_PRE_COMMIT;
466 else
467 graph->state = GRAPH_COMMIT;
@@ -538,7 +540,8 @@ static void graph_output_skip_line(struct git_graph *graph, struct strbuf *sb)
540 strbuf_addstr(sb, "...");
541 graph_pad_horizontally(graph, sb);
542
541 - if (graph->num_parents >= 3)
543 + if (graph->num_parents >= 3 &&
544 + graph->commit_index < (graph->num_columns - 1))
545 graph_update_state(graph, GRAPH_PRE_COMMIT);
546 else
547 graph_update_state(graph, GRAPH_COMMIT);