@matheusbsbs / matheus-bagliano / commits / 3c68d67b57
Fork 0

Fix output of "git log --graph --boundary"

Previously the graphing API wasn't aware of the revs->boundary flag, and it always assumed that commits marked UNINTERESTING would not be displayed. As a result, the boundary commits were printed at the end of the log output, but they didn't have any branch lines connecting them to their children in the graph. There was also another bug in the get_revision() code that caused graph_update() to be called twice on the first boundary commit. This caused the graph API to think that a commit had been skipped, and print a "..." line in the output. Signed-off-by: Adam Simpkins <adam@adamsimpkins.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Adam Simpkins committed May 24, 2008 at 16:02 UTC 3c68d67b572bce7ff41de463e75ee093e9dd71b7
2 files changed +67 -14
graph.c
+66 -13
@@ -189,8 +189,25 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)
189 * Returns 1 if the commit will be printed in the graph output,
190 * and 0 otherwise.
191 */
192 -static int graph_is_interesting(struct commit *commit)
192 +static int graph_is_interesting(struct git_graph *graph, struct commit *commit)
193 {
194 + /*
195 + * If revs->boundary is set, commits whose children have
196 + * been shown are always interesting, even if they have the
197 + * UNINTERESTING or TREESAME flags set.
198 + *
199 + * However, ignore the commit if SHOWN is set. If SHOWN is set,
200 + * the commit is interesting, but it has already been printed.
201 + * This can happen because get_revision() doesn't return the
202 + * boundary commits in topological order, even when
203 + * revs->topo_order is set.
204 + */
205 + if (graph->revs && graph->revs->boundary) {
206 + if ((commit->object.flags & (SHOWN | CHILD_SHOWN)) ==
207 + CHILD_SHOWN)
208 + return 1;
209 + }
210 +
211 /*
212 * Uninteresting and pruned commits won't be printed
213 */
@@ -206,7 +223,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
223 /*
224 * Ignore uinteresting commits
225 */
209 - if (!graph_is_interesting(commit))
226 + if (!graph_is_interesting(graph, commit))
227 return;
228
229 /*
@@ -380,7 +397,7 @@ void graph_update(struct git_graph *graph, struct commit *commit)
397 */
398 graph->num_parents = 0;
399 for (parent = commit->parents; parent; parent = parent->next) {
383 - if (graph_is_interesting(parent->item))
400 + if (graph_is_interesting(graph, parent->item))
401 graph->num_parents++;
402 }
403
@@ -543,6 +560,51 @@ static void graph_output_pre_commit_line(struct git_graph *graph,
560 graph->state = GRAPH_COMMIT;
561 }
562
563 +static void graph_output_commit_char(struct git_graph *graph, struct strbuf *sb)
564 +{
565 + /*
566 + * For boundary commits, print 'o'
567 + * (We should only see boundary commits when revs->boundary is set.)
568 + */
569 + if (graph->commit->object.flags & BOUNDARY) {
570 + assert(graph->revs->boundary);
571 + strbuf_addch(sb, 'o');
572 + return;
573 + }
574 +
575 + /*
576 + * If revs->left_right is set, print '<' for commits that
577 + * come from the left side, and '>' for commits from the right
578 + * side.
579 + */
580 + if (graph->revs && graph->revs->left_right) {
581 + if (graph->commit->object.flags & SYMMETRIC_LEFT)
582 + strbuf_addch(sb, '<');
583 + else
584 + strbuf_addch(sb, '>');
585 + return;
586 + }
587 +
588 + /*
589 + * Print 'M' for merge commits
590 + *
591 + * Note that we don't check graph->num_parents to determine if the
592 + * commit is a merge, since that only tracks the number of
593 + * "interesting" parents. We want to print 'M' for merge commits
594 + * even if they have less than 2 interesting parents.
595 + */
596 + if (graph->commit->parents != NULL &&
597 + graph->commit->parents->next != NULL) {
598 + strbuf_addch(sb, 'M');
599 + return;
600 + }
601 +
602 + /*
603 + * Print '*' in all other cases
604 + */
605 + strbuf_addch(sb, '*');
606 +}
607 +
608 void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb)
609 {
610 int seen_this = 0;
@@ -568,16 +630,7 @@ void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb)
630
631 if (col_commit == graph->commit) {
632 seen_this = 1;
571 -
572 - if (graph->revs && graph->revs->left_right) {
573 - if (graph->commit->object.flags & SYMMETRIC_LEFT)
574 - strbuf_addch(sb, '<');
575 - else
576 - strbuf_addch(sb, '>');
577 - } else if (graph->num_parents > 1)
578 - strbuf_addch(sb, 'M');
579 - else
580 - strbuf_addch(sb, '*');
633 + graph_output_commit_char(graph, sb);
634
635 if (graph->num_parents < 2)
636 strbuf_addch(sb, ' ');
revision.c
+1 -1
@@ -1697,7 +1697,7 @@ static struct commit *get_revision_internal(struct rev_info *revs)
1697 * switch to boundary commits output mode.
1698 */
1699 revs->boundary = 2;
1700 - return get_revision(revs);
1700 + return get_revision_internal(revs);
1701 }
1702
1703 /*