Merge branch 'rj/test-regex' into maint-1.7.11
[git.git] / revision.c
index 9a0d9c7de2af43c7ae082a892a2a9cfd6f4b4761..72104962d36b9672fd9dfc6ec850c99ccfc3803c 100644 (file)
@@ -345,6 +345,7 @@ static int tree_difference = REV_TREE_SAME;
 static void file_add_remove(struct diff_options *options,
                    int addremove, unsigned mode,
                    const unsigned char *sha1,
+                   int sha1_valid,
                    const char *fullpath, unsigned dirty_submodule)
 {
        int diff = addremove == '+' ? REV_TREE_NEW : REV_TREE_OLD;
@@ -358,6 +359,7 @@ static void file_change(struct diff_options *options,
                 unsigned old_mode, unsigned new_mode,
                 const unsigned char *old_sha1,
                 const unsigned char *new_sha1,
+                int old_sha1_valid, int new_sha1_valid,
                 const char *fullpath,
                 unsigned old_dirty_submodule, unsigned new_dirty_submodule)
 {
@@ -1132,15 +1134,27 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs,
                const char *this = arg;
                int symmetric = *next == '.';
                unsigned int flags_exclude = flags ^ UNINTERESTING;
+               static const char head_by_default[] = "HEAD";
                unsigned int a_flags;
 
                *dotdot = 0;
                next += symmetric;
 
                if (!*next)
-                       next = "HEAD";
+                       next = head_by_default;
                if (dotdot == arg)
-                       this = "HEAD";
+                       this = head_by_default;
+               if (this == head_by_default && next == head_by_default &&
+                   !symmetric) {
+                       /*
+                        * Just ".."?  That is not a range but the
+                        * pathspec for the parent directory.
+                        */
+                       if (!cant_be_filename) {
+                               *dotdot = '.';
+                               return -1;
+                       }
+               }
                if (!get_sha1(this, from_sha1) &&
                    !get_sha1(next, sha1)) {
                        struct commit *a, *b;
@@ -1358,11 +1372,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->topo_order = 1;
        } else if (!strcmp(arg, "--simplify-merges")) {
                revs->simplify_merges = 1;
+               revs->topo_order = 1;
                revs->rewrite_parents = 1;
                revs->simplify_history = 0;
                revs->limited = 1;
        } else if (!strcmp(arg, "--simplify-by-decoration")) {
                revs->simplify_merges = 1;
+               revs->topo_order = 1;
                revs->rewrite_parents = 1;
                revs->simplify_history = 0;
                revs->simplify_by_decoration = 1;
@@ -1781,7 +1797,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
                         * but the latter we have checked in the main loop.
                         */
                        for (j = i; j < argc; j++)
-                               verify_filename(revs->prefix, argv[j]);
+                               verify_filename(revs->prefix, argv[j], j == i);
 
                        append_prune_data(&prune_data, argv + i);
                        break;
@@ -1851,8 +1867,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
        if (revs->combine_merges)
                revs->ignore_merges = 0;
        revs->diffopt.abbrev = revs->abbrev;
-       if (diff_setup_done(&revs->diffopt) < 0)
-               die("diff_setup_done failed");
+       diff_setup_done(&revs->diffopt);
 
        compile_grep_patterns(&revs->grep_filter);
 
@@ -1947,8 +1962,9 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
        }
 
        /*
-        * Do we know what commit all of our parents should be rewritten to?
-        * Otherwise we are not ready to rewrite this one yet.
+        * Do we know what commit all of our parents that matter
+        * should be rewritten to?  Otherwise we are not ready to
+        * rewrite this one yet.
         */
        for (cnt = 0, p = commit->parents; p; p = p->next) {
                pst = locate_simplify_state(revs, p->item);
@@ -1956,6 +1972,8 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
                        tail = &commit_list_insert(p->item, tail)->next;
                        cnt++;
                }
+               if (revs->first_parent_only)
+                       break;
        }
        if (cnt) {
                tail = &commit_list_insert(commit, tail)->next;
@@ -1968,8 +1986,13 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
        for (p = commit->parents; p; p = p->next) {
                pst = locate_simplify_state(revs, p->item);
                p->item = pst->simplified;
+               if (revs->first_parent_only)
+                       break;
        }
-       cnt = remove_duplicate_parents(commit);
+       if (!revs->first_parent_only)
+               cnt = remove_duplicate_parents(commit);
+       else
+               cnt = 1;
 
        /*
         * It is possible that we are a merge and one side branch
@@ -2013,25 +2036,31 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
 
 static void simplify_merges(struct rev_info *revs)
 {
-       struct commit_list *list;
+       struct commit_list *list, *next;
        struct commit_list *yet_to_do, **tail;
+       struct commit *commit;
 
-       if (!revs->topo_order)
-               sort_in_topological_order(&revs->commits, revs->lifo);
        if (!revs->prune)
                return;
 
        /* feed the list reversed */
        yet_to_do = NULL;
-       for (list = revs->commits; list; list = list->next)
-               commit_list_insert(list->item, &yet_to_do);
+       for (list = revs->commits; list; list = next) {
+               commit = list->item;
+               next = list->next;
+               /*
+                * Do not free(list) here yet; the original list
+                * is used later in this function.
+                */
+               commit_list_insert(commit, &yet_to_do);
+       }
        while (yet_to_do) {
                list = yet_to_do;
                yet_to_do = NULL;
                tail = &yet_to_do;
                while (list) {
-                       struct commit *commit = list->item;
-                       struct commit_list *next = list->next;
+                       commit = list->item;
+                       next = list->next;
                        free(list);
                        list = next;
                        tail = simplify_one(revs, commit, tail);
@@ -2043,9 +2072,10 @@ static void simplify_merges(struct rev_info *revs)
        revs->commits = NULL;
        tail = &revs->commits;
        while (list) {
-               struct commit *commit = list->item;
-               struct commit_list *next = list->next;
                struct merge_simplify_state *st;
+
+               commit = list->item;
+               next = list->next;
                free(list);
                list = next;
                st = locate_simplify_state(revs, commit);
@@ -2066,10 +2096,16 @@ static void set_children(struct rev_info *revs)
        }
 }
 
+void reset_revision_walk(void)
+{
+       clear_object_flags(SEEN | ADDED | SHOWN);
+}
+
 int prepare_revision_walk(struct rev_info *revs)
 {
        int nr = revs->pending.nr;
        struct object_array_entry *e, *list;
+       struct commit_list **next = &revs->commits;
 
        e = list = revs->pending.objects;
        revs->pending.nr = 0;
@@ -2080,11 +2116,12 @@ int prepare_revision_walk(struct rev_info *revs)
                if (commit) {
                        if (!(commit->object.flags & SEEN)) {
                                commit->object.flags |= SEEN;
-                               commit_list_insert_by_date(commit, &revs->commits);
+                               next = commit_list_append(commit, next);
                        }
                }
                e++;
        }
+       commit_list_sort_by_date(&revs->commits);
        if (!revs->leak_pending)
                free(list);