in_merge_bases(): support only one "other" commit

In early days of its life, I planned to make it possible to compute "is a commit contained in all of these other commits?" with this function, but it turned out that no caller needed it. Just make it take two commit objects and add a comment to say what these two functions do. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 27, 2012 at 14:46 UTC a20efee9cfcf9c68bb01d0aa82ffc7903d88bab4
7 files changed +21 -18
builtin/branch.c
+2 -2
@@ -122,7 +122,7 @@ static int branch_merged(int kind, const char *name,
122 if (!reference_rev)
123 reference_rev = head_rev;
124
125 - merged = in_merge_bases(rev, &reference_rev, 1);
125 + merged = in_merge_bases(rev, reference_rev);
126
127 /*
128 * After the safety valve is fully redefined to "check with
@@ -132,7 +132,7 @@ static int branch_merged(int kind, const char *name,
132 * a gentle reminder is in order.
133 */
134 if ((head_rev != reference_rev) &&
135 - in_merge_bases(rev, &head_rev, 1) != merged) {
135 + in_merge_bases(rev, head_rev) != merged) {
136 if (merged)
137 warning(_("deleting branch '%s' that has been merged to\n"
138 " '%s', but not yet merged to HEAD."),
builtin/fetch.c
+1 -1
@@ -314,7 +314,7 @@ static int update_local_ref(struct ref *ref,
314 return r;
315 }
316
317 - if (in_merge_bases(current, &updated, 1)) {
317 + if (in_merge_bases(current, updated)) {
318 char quickref[83];
319 int r;
320 strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
commit.c
+9 -6
@@ -754,6 +754,9 @@ struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
754 return get_merge_bases_many(one, 1, &two, cleanup);
755 }
756
757 +/*
758 + * Is "commit" a decendant of one of the elements on the "with_commit" list?
759 + */
760 int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
761 {
762 if (!with_commit)
@@ -763,21 +766,21 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
766
767 other = with_commit->item;
768 with_commit = with_commit->next;
766 - if (in_merge_bases(other, &commit, 1))
769 + if (in_merge_bases(other, commit))
770 return 1;
771 }
772 return 0;
773 }
774
772 -int in_merge_bases(struct commit *commit, struct commit **reference, int num)
775 +/*
776 + * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
777 + */
778 +int in_merge_bases(struct commit *commit, struct commit *reference)
779 {
780 struct commit_list *bases, *b;
781 int ret = 0;
782
777 - if (num == 1)
778 - bases = get_merge_bases(commit, *reference, 1);
779 - else
780 - die("not yet");
783 + bases = get_merge_bases(commit, reference, 1);
784 for (b = bases; b; b = b->next) {
785 if (!hashcmp(commit->object.sha1, b->item->object.sha1)) {
786 ret = 1;
commit.h
+1 -1
@@ -168,7 +168,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
168 int depth, int shallow_flag, int not_shallow_flag);
169
170 int is_descendant_of(struct commit *, struct commit_list *);
171 -int in_merge_bases(struct commit *, struct commit **, int);
171 +int in_merge_bases(struct commit *, struct commit *);
172
173 extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
174 extern int run_add_interactive(const char *revision, const char *patch_mode,
contrib/examples/builtin-fetch--tool.c
+1 -1
@@ -96,7 +96,7 @@ static int update_local_ref(const char *name,
96 strcpy(oldh, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
97 strcpy(newh, find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
98
99 - if (in_merge_bases(current, &updated, 1)) {
99 + if (in_merge_bases(current, updated)) {
100 fprintf(stderr, "* %s: fast-forward to %s\n",
101 name, note);
102 fprintf(stderr, " old..new: %s..%s\n", oldh, newh);
fast-import.c
+1 -1
@@ -1691,7 +1691,7 @@ static int update_branch(struct branch *b)
1691 return error("Branch %s is missing commits.", b->name);
1692 }
1693
1694 - if (!in_merge_bases(old_cmit, &new_cmit, 1)) {
1694 + if (!in_merge_bases(old_cmit, new_cmit)) {
1695 unlock_ref(lock);
1696 warning("Not updating %s"
1697 " (new tip %s does not contain %s)",
submodule.c
+6 -6
@@ -738,7 +738,7 @@ static int find_first_merges(struct object_array *result, const char *path,
738 die("revision walk setup failed");
739 while ((commit = get_revision(&revs)) != NULL) {
740 struct object *o = &(commit->object);
741 - if (in_merge_bases(b, &commit, 1))
741 + if (in_merge_bases(b, commit))
742 add_object_array(o, NULL, &merges);
743 }
744
@@ -752,7 +752,7 @@ static int find_first_merges(struct object_array *result, const char *path,
752 contains_another = 0;
753 for (j = 0; j < merges.nr; j++) {
754 struct commit *m2 = (struct commit *) merges.objects[j].item;
755 - if (i != j && in_merge_bases(m2, &m1, 1)) {
755 + if (i != j && in_merge_bases(m2, m1)) {
756 contains_another = 1;
757 break;
758 }
@@ -814,18 +814,18 @@ int merge_submodule(unsigned char result[20], const char *path,
814 }
815
816 /* check whether both changes are forward */
817 - if (!in_merge_bases(commit_base, &commit_a, 1) ||
818 - !in_merge_bases(commit_base, &commit_b, 1)) {
817 + if (!in_merge_bases(commit_base, commit_a) ||
818 + !in_merge_bases(commit_base, commit_b)) {
819 MERGE_WARNING(path, "commits don't follow merge-base");
820 return 0;
821 }
822
823 /* Case #1: a is contained in b or vice versa */
824 - if (in_merge_bases(commit_a, &commit_b, 1)) {
824 + if (in_merge_bases(commit_a, commit_b)) {
825 hashcpy(result, b);
826 return 1;
827 }
828 - if (in_merge_bases(commit_b, &commit_a, 1)) {
828 + if (in_merge_bases(commit_b, commit_a)) {
829 hashcpy(result, a);
830 return 1;
831 }