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>
This commit is contained in:
Junio C Hamano 2012-08-27 14:46:01 -07:00
Родитель d0f1ea6003
Коммит a20efee9cf
7 изменённых файлов: 21 добавлений и 18 удалений

Просмотреть файл

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

Просмотреть файл

@ -314,7 +314,7 @@ static int update_local_ref(struct ref *ref,
return r;
}
if (in_merge_bases(current, &updated, 1)) {
if (in_merge_bases(current, updated)) {
char quickref[83];
int r;
strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));

Просмотреть файл

@ -754,6 +754,9 @@ struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
return get_merge_bases_many(one, 1, &two, cleanup);
}
/*
* Is "commit" a decendant of one of the elements on the "with_commit" list?
*/
int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
{
if (!with_commit)
@ -763,21 +766,21 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
other = with_commit->item;
with_commit = with_commit->next;
if (in_merge_bases(other, &commit, 1))
if (in_merge_bases(other, commit))
return 1;
}
return 0;
}
int in_merge_bases(struct commit *commit, struct commit **reference, int num)
/*
* Is "commit" an ancestor of (i.e. reachable from) the "reference"?
*/
int in_merge_bases(struct commit *commit, struct commit *reference)
{
struct commit_list *bases, *b;
int ret = 0;
if (num == 1)
bases = get_merge_bases(commit, *reference, 1);
else
die("not yet");
bases = get_merge_bases(commit, reference, 1);
for (b = bases; b; b = b->next) {
if (!hashcmp(commit->object.sha1, b->item->object.sha1)) {
ret = 1;

Просмотреть файл

@ -168,7 +168,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
int is_descendant_of(struct commit *, struct commit_list *);
int in_merge_bases(struct commit *, struct commit **, int);
int in_merge_bases(struct commit *, struct commit *);
extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
extern int run_add_interactive(const char *revision, const char *patch_mode,

Просмотреть файл

@ -96,7 +96,7 @@ static int update_local_ref(const char *name,
strcpy(oldh, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
strcpy(newh, find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
if (in_merge_bases(current, &updated, 1)) {
if (in_merge_bases(current, updated)) {
fprintf(stderr, "* %s: fast-forward to %s\n",
name, note);
fprintf(stderr, " old..new: %s..%s\n", oldh, newh);

Просмотреть файл

@ -1691,7 +1691,7 @@ static int update_branch(struct branch *b)
return error("Branch %s is missing commits.", b->name);
}
if (!in_merge_bases(old_cmit, &new_cmit, 1)) {
if (!in_merge_bases(old_cmit, new_cmit)) {
unlock_ref(lock);
warning("Not updating %s"
" (new tip %s does not contain %s)",

Просмотреть файл

@ -738,7 +738,7 @@ static int find_first_merges(struct object_array *result, const char *path,
die("revision walk setup failed");
while ((commit = get_revision(&revs)) != NULL) {
struct object *o = &(commit->object);
if (in_merge_bases(b, &commit, 1))
if (in_merge_bases(b, commit))
add_object_array(o, NULL, &merges);
}
@ -752,7 +752,7 @@ static int find_first_merges(struct object_array *result, const char *path,
contains_another = 0;
for (j = 0; j < merges.nr; j++) {
struct commit *m2 = (struct commit *) merges.objects[j].item;
if (i != j && in_merge_bases(m2, &m1, 1)) {
if (i != j && in_merge_bases(m2, m1)) {
contains_another = 1;
break;
}
@ -814,18 +814,18 @@ int merge_submodule(unsigned char result[20], const char *path,
}
/* check whether both changes are forward */
if (!in_merge_bases(commit_base, &commit_a, 1) ||
!in_merge_bases(commit_base, &commit_b, 1)) {
if (!in_merge_bases(commit_base, commit_a) ||
!in_merge_bases(commit_base, commit_b)) {
MERGE_WARNING(path, "commits don't follow merge-base");
return 0;
}
/* Case #1: a is contained in b or vice versa */
if (in_merge_bases(commit_a, &commit_b, 1)) {
if (in_merge_bases(commit_a, commit_b)) {
hashcpy(result, b);
return 1;
}
if (in_merge_bases(commit_b, &commit_a, 1)) {
if (in_merge_bases(commit_b, commit_a)) {
hashcpy(result, a);
return 1;
}