pull --rebase: exit early when the working directory is dirty
[gitweb.git] / revision.c
index 63bf2c5c2dd314cfff2f54f76c4f5fd85b3b207e..7142cf96cde81377522e49de5f102a25eaec2d54 100644 (file)
@@ -6,6 +6,7 @@
 #include "diff.h"
 #include "refs.h"
 #include "revision.h"
+#include "graph.h"
 #include "grep.h"
 #include "reflog-walk.h"
 #include "patch-ids.h"
@@ -415,7 +416,6 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
 {
        struct commit_list *parent = commit->parents;
        unsigned left_flag;
-       int add, rest;
 
        if (commit->object.flags & ADDED)
                return 0;
@@ -462,19 +462,18 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
 
        left_flag = (commit->object.flags & SYMMETRIC_LEFT);
 
-       rest = !revs->first_parent_only;
-       for (parent = commit->parents, add = 1; parent; add = rest) {
+       for (parent = commit->parents; parent; parent = parent->next) {
                struct commit *p = parent->item;
 
-               parent = parent->next;
                if (parse_commit(p) < 0)
                        return -1;
                p->object.flags |= left_flag;
-               if (p->object.flags & SEEN)
-                       continue;
-               p->object.flags |= SEEN;
-               if (add)
+               if (!(p->object.flags & SEEN)) {
+                       p->object.flags |= SEEN;
                        insert_by_date(p, list);
+               }
+               if(revs->first_parent_only)
+                       break;
        }
        return 0;
 }
@@ -564,14 +563,39 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
        free_patch_ids(&ids);
 }
 
-static void add_to_list(struct commit_list **p, struct commit *commit, struct commit_list *n)
+/* How many extra uninteresting commits we want to see.. */
+#define SLOP 5
+
+static int still_interesting(struct commit_list *src, unsigned long date, int slop)
 {
-       p = &commit_list_insert(commit, p)->next;
-       *p = n;
+       /*
+        * No source list at all? We're definitely done..
+        */
+       if (!src)
+               return 0;
+
+       /*
+        * Does the destination list contain entries with a date
+        * before the source list? Definitely _not_ done.
+        */
+       if (date < src->item->date)
+               return SLOP;
+
+       /*
+        * Does the source list still have interesting commits in
+        * it? Definitely not done..
+        */
+       if (!everybody_uninteresting(src))
+               return SLOP;
+
+       /* Ok, we're closing in.. */
+       return slop-1;
 }
 
 static int limit_list(struct rev_info *revs)
 {
+       int slop = SLOP;
+       unsigned long date = ~0ul;
        struct commit_list *list = revs->commits;
        struct commit_list *newlist = NULL;
        struct commit_list **p = &newlist;
@@ -591,16 +615,19 @@ static int limit_list(struct rev_info *revs)
                        return -1;
                if (obj->flags & UNINTERESTING) {
                        mark_parents_uninteresting(commit);
-                       if (everybody_uninteresting(list)) {
-                               if (revs->show_all)
-                                       add_to_list(p, commit, list);
-                               break;
-                       }
-                       if (!revs->show_all)
-                               continue;
+                       if (revs->show_all)
+                               p = &commit_list_insert(commit, p)->next;
+                       slop = still_interesting(list, date, slop);
+                       if (slop)
+                               continue;
+                       /* If showing all, add the whole pending list to the end */
+                       if (revs->show_all)
+                               *p = list;
+                       break;
                }
                if (revs->min_age != -1 && (commit->date > revs->min_age))
                        continue;
+               date = commit->date;
                p = &commit_list_insert(commit, p)->next;
 
                show = show_early_output;
@@ -1055,6 +1082,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                                continue;
                        }
                        if (!strcmp(arg, "--topo-order")) {
+                               revs->lifo = 1;
                                revs->topo_order = 1;
                                continue;
                        }
@@ -1076,7 +1104,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                                }
                        }
                        if (!strcmp(arg, "--parents")) {
-                               revs->parents = 1;
+                               revs->rewrite_parents = 1;
+                               revs->print_parents = 1;
                                continue;
                        }
                        if (!strcmp(arg, "--dense")) {
@@ -1170,7 +1199,13 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                        }
                        if (!prefixcmp(arg, "--pretty")) {
                                revs->verbose_header = 1;
-                               revs->commit_format = get_commit_format(arg+8);
+                               get_commit_format(arg+8, revs);
+                               continue;
+                       }
+                       if (!prefixcmp(arg, "--graph")) {
+                               revs->topo_order = 1;
+                               revs->rewrite_parents = 1;
+                               revs->graph = graph_init();
                                continue;
                        }
                        if (!strcmp(arg, "--root")) {
@@ -1367,6 +1402,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
        if (revs->reverse && revs->reflog_info)
                die("cannot combine --reverse with --walk-reflogs");
 
+       /*
+        * Limitations on the graph functionality
+        */
+       if (revs->reverse && revs->graph)
+               die("cannot combine --reverse with --graph");
+
+       if (revs->reflog_info && revs->graph)
+               die("cannot combine --walk-reflogs with --graph");
+
        return left;
 }
 
@@ -1495,13 +1539,13 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
                /* Commit without changes? */
                if (commit->object.flags & TREESAME) {
                        /* drop merges unless we want parenthood */
-                       if (!revs->parents)
+                       if (!revs->rewrite_parents)
                                return commit_ignore;
                        /* non-merge - always ignore it */
                        if (!commit->parents || !commit->parents->next)
                                return commit_ignore;
                }
-               if (revs->parents && rewrite_parents(revs, commit) < 0)
+               if (revs->rewrite_parents && rewrite_parents(revs, commit) < 0)
                        return commit_error;
        }
        return commit_show;
@@ -1568,7 +1612,7 @@ static void gc_boundary(struct object_array *array)
        }
 }
 
-struct commit *get_revision(struct rev_info *revs)
+static struct commit *get_revision_internal(struct rev_info *revs)
 {
        struct commit *c = NULL;
        struct commit_list *l;
@@ -1675,3 +1719,11 @@ struct commit *get_revision(struct rev_info *revs)
 
        return c;
 }
+
+struct commit *get_revision(struct rev_info *revs)
+{
+       struct commit *c = get_revision_internal(revs);
+       if (c && revs->graph)
+               graph_update(revs->graph, c);
+       return c;
+}