Skip to content

Commit a20efee

Browse files
committed
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 <[email protected]>
1 parent d0f1ea6 commit a20efee

File tree

7 files changed

+21
-18
lines changed

7 files changed

+21
-18
lines changed

builtin/branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static int branch_merged(int kind, const char *name,
122122
if (!reference_rev)
123123
reference_rev = head_rev;
124124

125-
merged = in_merge_bases(rev, &reference_rev, 1);
125+
merged = in_merge_bases(rev, reference_rev);
126126

127127
/*
128128
* After the safety valve is fully redefined to "check with
@@ -132,7 +132,7 @@ static int branch_merged(int kind, const char *name,
132132
* a gentle reminder is in order.
133133
*/
134134
if ((head_rev != reference_rev) &&
135-
in_merge_bases(rev, &head_rev, 1) != merged) {
135+
in_merge_bases(rev, head_rev) != merged) {
136136
if (merged)
137137
warning(_("deleting branch '%s' that has been merged to\n"
138138
" '%s', but not yet merged to HEAD."),

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static int update_local_ref(struct ref *ref,
314314
return r;
315315
}
316316

317-
if (in_merge_bases(current, &updated, 1)) {
317+
if (in_merge_bases(current, updated)) {
318318
char quickref[83];
319319
int r;
320320
strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));

commit.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
754754
return get_merge_bases_many(one, 1, &two, cleanup);
755755
}
756756

757+
/*
758+
* Is "commit" a decendant of one of the elements on the "with_commit" list?
759+
*/
757760
int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
758761
{
759762
if (!with_commit)
@@ -763,21 +766,21 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
763766

764767
other = with_commit->item;
765768
with_commit = with_commit->next;
766-
if (in_merge_bases(other, &commit, 1))
769+
if (in_merge_bases(other, commit))
767770
return 1;
768771
}
769772
return 0;
770773
}
771774

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)
773779
{
774780
struct commit_list *bases, *b;
775781
int ret = 0;
776782

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);
781784
for (b = bases; b; b = b->next) {
782785
if (!hashcmp(commit->object.sha1, b->item->object.sha1)) {
783786
ret = 1;

commit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
168168
int depth, int shallow_flag, int not_shallow_flag);
169169

170170
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 *);
172172

173173
extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
174174
extern int run_add_interactive(const char *revision, const char *patch_mode,

contrib/examples/builtin-fetch--tool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int update_local_ref(const char *name,
9696
strcpy(oldh, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
9797
strcpy(newh, find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
9898

99-
if (in_merge_bases(current, &updated, 1)) {
99+
if (in_merge_bases(current, updated)) {
100100
fprintf(stderr, "* %s: fast-forward to %s\n",
101101
name, note);
102102
fprintf(stderr, " old..new: %s..%s\n", oldh, newh);

fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ static int update_branch(struct branch *b)
16911691
return error("Branch %s is missing commits.", b->name);
16921692
}
16931693

1694-
if (!in_merge_bases(old_cmit, &new_cmit, 1)) {
1694+
if (!in_merge_bases(old_cmit, new_cmit)) {
16951695
unlock_ref(lock);
16961696
warning("Not updating %s"
16971697
" (new tip %s does not contain %s)",

submodule.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ static int find_first_merges(struct object_array *result, const char *path,
738738
die("revision walk setup failed");
739739
while ((commit = get_revision(&revs)) != NULL) {
740740
struct object *o = &(commit->object);
741-
if (in_merge_bases(b, &commit, 1))
741+
if (in_merge_bases(b, commit))
742742
add_object_array(o, NULL, &merges);
743743
}
744744

@@ -752,7 +752,7 @@ static int find_first_merges(struct object_array *result, const char *path,
752752
contains_another = 0;
753753
for (j = 0; j < merges.nr; j++) {
754754
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)) {
756756
contains_another = 1;
757757
break;
758758
}
@@ -814,18 +814,18 @@ int merge_submodule(unsigned char result[20], const char *path,
814814
}
815815

816816
/* 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)) {
819819
MERGE_WARNING(path, "commits don't follow merge-base");
820820
return 0;
821821
}
822822

823823
/* 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)) {
825825
hashcpy(result, b);
826826
return 1;
827827
}
828-
if (in_merge_bases(commit_b, &commit_a, 1)) {
828+
if (in_merge_bases(commit_b, commit_a)) {
829829
hashcpy(result, a);
830830
return 1;
831831
}

0 commit comments

Comments
 (0)