get_merge_bases(): always clean-up object flags
authorJunio C Hamano <gitster@pobox.com>
Thu, 30 Oct 2014 19:20:44 +0000 (12:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Oct 2014 19:51:10 +0000 (12:51 -0700)
The callers of get_merge_bases() can choose to leave object flags
used during the merge-base traversal by passing cleanup=0 as a
parameter, but in practice a very few callers can afford to do so
(namely, "git merge-base"), as they need to compute merge base in
preparation for other processing of their own and they need to see
the object without contaminate flags.

Change the function signature of get_merge_bases_many() and
get_merge_bases() to drop the cleanup parameter, so that the
majority of the callers do not have to say ", 1" at the end.

Give a new get_merge_bases_many_dirty() API to support only a few
callers that know they do not need to spend cycles cleaning up the
object flags.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
bisect.c
builtin/merge-base.c
builtin/merge.c
builtin/rev-parse.c
commit.c
commit.h
merge-recursive.c
notes-merge.c
revision.c
sha1_name.c
submodule.c
index 604c577caace56222ba19ff26495efc41f53ccdd..1d6b393f366069735727c08bbec85433dd7d7838 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -776,7 +776,7 @@ static void check_merge_bases(int no_checkout)
        int rev_nr;
        struct commit **rev = get_bad_and_good_commits(&rev_nr);
 
-       result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1, 1);
+       result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1);
 
        for (; result; result = result->next) {
                const unsigned char *mb = result->item->object.sha1;
index 0ecde8da30615996f54563014e4774b67812c531..fdebef6fa157e920a4560e68c1215665f1e20baf 100644 (file)
@@ -10,7 +10,7 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
 {
        struct commit_list *result;
 
-       result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1, 0);
+       result = get_merge_bases_many_dirty(rev[0], rev_nr - 1, rev + 1);
 
        if (!result)
                return 1;
@@ -176,7 +176,7 @@ static int handle_fork_point(int argc, const char **argv)
        for (i = 0; i < revs.nr; i++)
                revs.commit[i]->object.flags &= ~TMP_MARK;
 
-       bases = get_merge_bases_many(derived, revs.nr, revs.commit, 0);
+       bases = get_merge_bases_many_dirty(derived, revs.nr, revs.commit);
 
        /*
         * There should be one and only one merge base, when we found
index 8763b2efa2d7e3d7af49e9bc160a67239fbd3147..fbdbd78da18c2f6ac134a3ea5705ca1ac4da9a27 100644 (file)
@@ -1330,7 +1330,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (!remoteheads)
                ; /* already up-to-date */
        else if (!remoteheads->next)
-               common = get_merge_bases(head_commit, remoteheads->item, 1);
+               common = get_merge_bases(head_commit, remoteheads->item);
        else {
                struct commit_list *list = remoteheads;
                commit_list_insert(head_commit, &list);
@@ -1427,7 +1427,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                         * merge_bases again, otherwise "git merge HEAD^
                         * HEAD^^" would be missed.
                         */
-                       common_one = get_merge_bases(head_commit, j->item, 1);
+                       common_one = get_merge_bases(head_commit, j->item);
                        if (hashcmp(common_one->item->object.sha1,
                                j->item->object.sha1)) {
                                up_to_date = 0;
index 1a6122d3ae29609c30c26959fbb1ff799e13a4b2..ed6db3731afd69f6477f3c77f59c58cded0fb2d6 100644 (file)
@@ -277,7 +277,7 @@ static int try_difference(const char *arg)
                        struct commit *a, *b;
                        a = lookup_commit_reference(sha1);
                        b = lookup_commit_reference(end);
-                       exclude = get_merge_bases(a, b, 1);
+                       exclude = get_merge_bases(a, b);
                        while (exclude) {
                                struct commit_list *n = exclude->next;
                                show_rev(REVERSED,
index 65179f96eecc85082f9bf3f0312676878d92861d..8f9f37e3e6d3372207b63191fe3853377099a2f1 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -883,7 +883,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
 
                for (j = ret; j; j = j->next) {
                        struct commit_list *bases;
-                       bases = get_merge_bases(i->item, j->item, 1);
+                       bases = get_merge_bases(i->item, j->item);
                        if (!new)
                                new = bases;
                        else
@@ -952,10 +952,10 @@ static int remove_redundant(struct commit **array, int cnt)
        return filled;
 }
 
-struct commit_list *get_merge_bases_many(struct commit *one,
-                                        int n,
-                                        struct commit **twos,
-                                        int cleanup)
+static struct commit_list *get_merge_bases_many_0(struct commit *one,
+                                                 int n,
+                                                 struct commit **twos,
+                                                 int cleanup)
 {
        struct commit_list *list;
        struct commit **rslt;
@@ -998,10 +998,23 @@ struct commit_list *get_merge_bases_many(struct commit *one,
        return result;
 }
 
-struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
-                                   int cleanup)
+struct commit_list *get_merge_bases_many(struct commit *one,
+                                        int n,
+                                        struct commit **twos)
+{
+       return get_merge_bases_many_0(one, n, twos, 1);
+}
+
+struct commit_list *get_merge_bases_many_dirty(struct commit *one,
+                                              int n,
+                                              struct commit **twos)
+{
+       return get_merge_bases_many_0(one, n, twos, 0);
+}
+
+struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
 {
-       return get_merge_bases_many(one, 1, &two, cleanup);
+       return get_merge_bases_many_0(one, 1, &two, 1);
 }
 
 /*
index 2e1492a6e4d1c5fc5bea3a48180f128601c3461e..7cd45035818ed615230d333f653d3e1c1d6e387c 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -223,10 +223,13 @@ struct commit_graft *read_graft_line(char *buf, int len);
 int register_commit_graft(struct commit_graft *, int);
 struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
 
-extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
-extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
+extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
+extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);
 extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
+/* To be used only when object flags after this call no longer matter */
+extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n, struct commit **twos);
+
 /* largest positive number a signed 32-bit integer can contain */
 #define INFINITE_DEPTH 0x7fffffff
 
index d38a3b2eb5bf4b0940a2aa4d5c32f02b9f35cc15..0b7bb6d547b16ff124bac111d6d338bd3214b2e2 100644 (file)
@@ -1904,7 +1904,7 @@ int merge_recursive(struct merge_options *o,
        }
 
        if (!ca) {
-               ca = get_merge_bases(h1, h2, 1);
+               ca = get_merge_bases(h1, h2);
                ca = reverse_commit_list(ca);
        }
 
index fd5fae255d2760d6b7895e95cee627b5e28f776e..c6de891e499f0c37452d186649ed09953542d6a2 100644 (file)
@@ -594,7 +594,7 @@ int notes_merge(struct notes_merge_options *o,
        assert(local && remote);
 
        /* Find merge bases */
-       bases = get_merge_bases(local, remote, 1);
+       bases = get_merge_bases(local, remote);
        if (!bases) {
                base_sha1 = null_sha1;
                base_tree_sha1 = EMPTY_TREE_SHA1_BIN;
index 2571ada6bf66ce6e945c539be4b0123e5b9648a9..07a8ca1ac682ce06cd0fc3ec796990937fcb65df 100644 (file)
@@ -1383,7 +1383,7 @@ static void prepare_show_merge(struct rev_info *revs)
        other = lookup_commit_or_die(sha1, "MERGE_HEAD");
        add_pending_object(revs, &head->object, "HEAD");
        add_pending_object(revs, &other->object, "MERGE_HEAD");
-       bases = get_merge_bases(head, other, 1);
+       bases = get_merge_bases(head, other);
        add_rev_cmdline_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING | BOTTOM);
        add_pending_commit_list(revs, bases, UNINTERESTING | BOTTOM);
        free_commit_list(bases);
@@ -1488,7 +1488,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
                                     : lookup_commit_reference(b_obj->sha1));
                                if (!a || !b)
                                        goto missing;
-                               exclude = get_merge_bases(a, b, 1);
+                               exclude = get_merge_bases(a, b);
                                add_rev_cmdline_list(revs, exclude,
                                                     REV_CMD_MERGE_BASE,
                                                     flags_exclude);
index c2c938c4e161fc6849a87a7a19336712f36f74ff..3e9e86cbee6738312421ff2418c04d402c350bff 100644 (file)
@@ -987,7 +987,7 @@ int get_sha1_mb(const char *name, unsigned char *sha1)
        two = lookup_commit_reference_gently(sha1_tmp, 0);
        if (!two)
                return -1;
-       mbs = get_merge_bases(one, two, 1);
+       mbs = get_merge_bases(one, two);
        if (!mbs || mbs->next)
                st = -1;
        else {
index b80ecacf60dc87025336b6b6d6a51acc9321f429..10b2ddb870f6a80cca6ebba977238c88f3aaf767 100644 (file)
@@ -301,7 +301,7 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
        left->object.flags |= SYMMETRIC_LEFT;
        add_pending_object(rev, &left->object, path);
        add_pending_object(rev, &right->object, path);
-       merge_bases = get_merge_bases(left, right, 1);
+       merge_bases = get_merge_bases(left, right);
        if (merge_bases) {
                if (merge_bases->item == left)
                        *fast_forward = 1;