]> asedeno.scripts.mit.edu Git - git.git/blobdiff - graph.c
Merge branch 'as/graph'
[git.git] / graph.c
diff --git a/graph.c b/graph.c
index add7e4477dfeb5715a13069d233365c8d2dce2c3..26b8c5209e280697cc35ffd5313fe3e79681fc43 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -54,6 +54,8 @@ struct git_graph {
         * The commit currently being processed
         */
        struct commit *commit;
+       /* The rev-info used for the current traversal */
+       struct rev_info *revs;
        /*
         * The number of interesting parents that this commit has.
         *
@@ -127,10 +129,11 @@ struct git_graph {
        int *new_mapping;
 };
 
-struct git_graph *graph_init(void)
+struct git_graph *graph_init(struct rev_info *opt)
 {
        struct git_graph *graph = xmalloc(sizeof(struct git_graph));
        graph->commit = NULL;
+       graph->revs = opt;
        graph->num_parents = 0;
        graph->expansion_row = 0;
        graph->state = GRAPH_PADDING;
@@ -186,8 +189,18 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)
  * Returns 1 if the commit will be printed in the graph output,
  * and 0 otherwise.
  */
-static int graph_is_interesting(struct commit *commit)
+static int graph_is_interesting(struct git_graph *graph, struct commit *commit)
 {
+       /*
+        * If revs->boundary is set, commits whose children have
+        * been shown are always interesting, even if they have the
+        * UNINTERESTING or TREESAME flags set.
+        */
+       if (graph->revs && graph->revs->boundary) {
+               if (commit->object.flags & CHILD_SHOWN)
+                       return 1;
+       }
+
        /*
         * Uninteresting and pruned commits won't be printed
         */
@@ -203,7 +216,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
        /*
         * Ignore uinteresting commits
         */
-       if (!graph_is_interesting(commit))
+       if (!graph_is_interesting(graph, commit))
                return;
 
        /*
@@ -377,7 +390,7 @@ void graph_update(struct git_graph *graph, struct commit *commit)
         */
        graph->num_parents = 0;
        for (parent = commit->parents; parent; parent = parent->next) {
-               if (graph_is_interesting(parent->item))
+               if (graph_is_interesting(graph, parent->item))
                        graph->num_parents++;
        }
 
@@ -540,6 +553,51 @@ static void graph_output_pre_commit_line(struct git_graph *graph,
                graph->state = GRAPH_COMMIT;
 }
 
+static void graph_output_commit_char(struct git_graph *graph, struct strbuf *sb)
+{
+       /*
+        * For boundary commits, print 'o'
+        * (We should only see boundary commits when revs->boundary is set.)
+        */
+       if (graph->commit->object.flags & BOUNDARY) {
+               assert(graph->revs->boundary);
+               strbuf_addch(sb, 'o');
+               return;
+       }
+
+       /*
+        * If revs->left_right is set, print '<' for commits that
+        * come from the left side, and '>' for commits from the right
+        * side.
+        */
+       if (graph->revs && graph->revs->left_right) {
+               if (graph->commit->object.flags & SYMMETRIC_LEFT)
+                       strbuf_addch(sb, '<');
+               else
+                       strbuf_addch(sb, '>');
+               return;
+       }
+
+       /*
+        * Print 'M' for merge commits
+        *
+        * Note that we don't check graph->num_parents to determine if the
+        * commit is a merge, since that only tracks the number of
+        * "interesting" parents.  We want to print 'M' for merge commits
+        * even if they have less than 2 interesting parents.
+        */
+       if (graph->commit->parents != NULL &&
+           graph->commit->parents->next != NULL) {
+               strbuf_addch(sb, 'M');
+               return;
+       }
+
+       /*
+        * Print '*' in all other cases
+        */
+       strbuf_addch(sb, '*');
+}
+
 void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb)
 {
        int seen_this = 0;
@@ -565,19 +623,7 @@ void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb)
 
                if (col_commit == graph->commit) {
                        seen_this = 1;
-                       /*
-                        * If the commit has more than 1 interesting
-                        * parent, print 'M' to indicate that it is a
-                        * merge.  Otherwise, print '*'.
-                        *
-                        * Note that even if this is actually a merge
-                        * commit, we still print '*' if less than 2 of its
-                        * parents are interesting.
-                        */
-                       if (graph->num_parents > 1)
-                               strbuf_addch(sb, 'M');
-                       else
-                               strbuf_addch(sb, '*');
+                       graph_output_commit_char(graph, sb);
 
                        if (graph->num_parents < 2)
                                strbuf_addch(sb, ' ');