Code

Add new test case to ensure git-merge reduces octopus parents when possible
[git.git] / builtin-rev-list.c
index f5149e59b7c04d943f3b90f706a66d185f8a396c..83a7b1349e06dbf1a355888272d9b13a7d4c22c4 100644 (file)
@@ -10,6 +10,7 @@
 #include "list-objects.h"
 #include "builtin.h"
 #include "log-tree.h"
+#include "graph.h"
 
 /* bits #0-15 in revision.h */
 
@@ -25,11 +26,15 @@ static const char rev_list_usage[] =
 "    --no-merges\n"
 "    --remove-empty\n"
 "    --all\n"
+"    --branches\n"
+"    --tags\n"
+"    --remotes\n"
 "    --stdin\n"
 "    --quiet\n"
 "  ordering output:\n"
 "    --topo-order\n"
 "    --date-order\n"
+"    --reverse\n"
 "  formatting output:\n"
 "    --parents\n"
 "    --objects | --objects-edge\n"
@@ -54,24 +59,31 @@ static const char *header_prefix;
 static void finish_commit(struct commit *commit);
 static void show_commit(struct commit *commit)
 {
+       graph_show_commit(revs.graph);
+
        if (show_timestamp)
                printf("%lu ", commit->date);
        if (header_prefix)
                fputs(header_prefix, stdout);
-       if (commit->object.flags & BOUNDARY)
-               putchar('-');
-       else if (revs.left_right) {
-               if (commit->object.flags & SYMMETRIC_LEFT)
-                       putchar('<');
-               else
-                       putchar('>');
+
+       if (!revs.graph) {
+               if (commit->object.flags & BOUNDARY)
+                       putchar('-');
+               else if (commit->object.flags & UNINTERESTING)
+                       putchar('^');
+               else if (revs.left_right) {
+                       if (commit->object.flags & SYMMETRIC_LEFT)
+                               putchar('<');
+                       else
+                               putchar('>');
+               }
        }
        if (revs.abbrev_commit && revs.abbrev)
                fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev),
                      stdout);
        else
                fputs(sha1_to_hex(commit->object.sha1), stdout);
-       if (revs.parents) {
+       if (revs.print_parents) {
                struct commit_list *parents = commit->parents;
                while (parents) {
                        printf(" %s", sha1_to_hex(parents->item->object.sha1));
@@ -84,15 +96,54 @@ static void show_commit(struct commit *commit)
        else
                putchar('\n');
 
-       if (revs.verbose_header) {
+       if (revs.verbose_header && commit->buffer) {
                struct strbuf buf;
                strbuf_init(&buf, 0);
                pretty_print_commit(revs.commit_format, commit,
                                    &buf, revs.abbrev, NULL, NULL,
                                    revs.date_mode, 0);
-               if (buf.len)
-                       printf("%s%c", buf.buf, hdr_termination);
+               if (revs.graph) {
+                       if (buf.len) {
+                               if (revs.commit_format != CMIT_FMT_ONELINE)
+                                       graph_show_oneline(revs.graph);
+
+                               graph_show_commit_msg(revs.graph, &buf);
+
+                               /*
+                                * Add a newline after the commit message.
+                                *
+                                * Usually, this newline produces a blank
+                                * padding line between entries, in which case
+                                * we need to add graph padding on this line.
+                                *
+                                * However, the commit message may not end in a
+                                * newline.  In this case the newline simply
+                                * ends the last line of the commit message,
+                                * and we don't need any graph output.  (This
+                                * always happens with CMIT_FMT_ONELINE, and it
+                                * happens with CMIT_FMT_USERFORMAT when the
+                                * format doesn't explicitly end in a newline.)
+                                */
+                               if (buf.len && buf.buf[buf.len - 1] == '\n')
+                                       graph_show_padding(revs.graph);
+                               putchar('\n');
+                       } else {
+                               /*
+                                * If the message buffer is empty, just show
+                                * the rest of the graph output for this
+                                * commit.
+                                */
+                               if (graph_show_remainder(revs.graph))
+                                       putchar('\n');
+                       }
+               } else {
+                       if (buf.len)
+                               printf("%s%c", buf.buf, hdr_termination);
+               }
                strbuf_release(&buf);
+       } else {
+               if (graph_show_remainder(revs.graph))
+                       putchar('\n');
        }
        maybe_flush_or_die(stdout, "stdout");
        finish_commit(commit);
@@ -153,7 +204,7 @@ static int count_distance(struct commit_list *entry)
 
                if (commit->object.flags & (UNINTERESTING | COUNTED))
                        break;
-               if (!revs.prune_fn || (commit->object.flags & TREECHANGE))
+               if (!(commit->object.flags & TREESAME))
                        nr++;
                commit->object.flags |= COUNTED;
                p = commit->parents;
@@ -209,7 +260,7 @@ static inline int halfway(struct commit_list *p, int nr)
        /*
         * Don't short-cut something we are not going to return!
         */
-       if (revs.prune_fn && !(p->item->object.flags & TREECHANGE))
+       if (p->item->object.flags & TREESAME)
                return 0;
        if (DEBUG_BISECT)
                return 0;
@@ -245,7 +296,7 @@ static void show_list(const char *debug, int counted, int nr,
                char *ep, *sp;
 
                fprintf(stderr, "%c%c%c ",
-                       (flags & TREECHANGE) ? 'T' : ' ',
+                       (flags & TREESAME) ? ' ' : 'T',
                        (flags & UNINTERESTING) ? 'U' : ' ',
                        (flags & COUNTED) ? 'C' : ' ');
                if (commit->util)
@@ -279,7 +330,7 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
                int distance;
                unsigned flags = p->item->object.flags;
 
-               if (revs.prune_fn && !(flags & TREECHANGE))
+               if (flags & TREESAME)
                        continue;
                distance = weight(p);
                if (nr - distance < distance)
@@ -319,7 +370,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
                int distance;
                unsigned flags = p->item->object.flags;
 
-               if (revs.prune_fn && !(flags & TREECHANGE))
+               if (flags & TREESAME)
                        continue;
                distance = weight(p);
                if (nr - distance < distance)
@@ -373,7 +424,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
                p->item->util = &weights[n++];
                switch (count_interesting_parents(commit)) {
                case 0:
-                       if (!revs.prune_fn || (flags & TREECHANGE)) {
+                       if (!(flags & TREESAME)) {
                                weight_set(p, 1);
                                counted++;
                                show_list("bisection 2 count one",
@@ -446,7 +497,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
                         * add one for p itself if p is to be counted,
                         * otherwise inherit it from q directly.
                         */
-                       if (!revs.prune_fn || (flags & TREECHANGE)) {
+                       if (!(flags & TREESAME)) {
                                weight_set(p, weight(q)+1);
                                counted++;
                                show_list("bisection 2 count one",
@@ -493,7 +544,7 @@ static struct commit_list *find_bisection(struct commit_list *list,
                        continue;
                p->next = last;
                last = p;
-               if (!revs.prune_fn || (flags & TREECHANGE))
+               if (!(flags & TREESAME))
                        nr++;
                on_list++;
        }
@@ -520,7 +571,7 @@ static void read_revisions_from_stdin(struct rev_info *revs)
 
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
-               if (line[len - 1] == '\n')
+               if (len && line[len - 1] == '\n')
                        line[--len] = 0;
                if (!len)
                        break;
@@ -540,7 +591,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
        int bisect_find_all = 0;
        int quiet = 0;
 
-       git_config(git_default_config);
+       git_config(git_default_config, NULL);
        init_revisions(&revs, prefix);
        revs.abbrev = 0;
        revs.commit_format = CMIT_FMT_UNSPECIFIED;
@@ -605,11 +656,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                usage(rev_list_usage);
 
        save_commit_buffer = revs.verbose_header || revs.grep_filter;
-       track_object_refs = 0;
        if (bisect_list)
                revs.limited = 1;
 
-       prepare_revision_walk(&revs);
+       if (prepare_revision_walk(&revs))
+               die("revision walk setup failed");
        if (revs.tree_objects)
                mark_edges_uninteresting(revs.commits, &revs, show_edge);