1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-08 21:26:08 +02:00

commit.c: add in_merge_bases_many()

Similar to in_merge_bases(commit, other) that returns true when
commit is an ancestor (i.e. in the merge bases between the two) of
the other commit, in_merge_bases_many(commit, n_other, other[])
checks if commit is an ancestor of any of the other[] commits.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2013-03-04 10:16:42 -08:00
parent e895cb5135
commit 4c4b27e8ce
2 changed files with 26 additions and 13 deletions

View File

@ -858,24 +858,36 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
return 0;
}
/*
* Is "commit" an ancestor of one of the "references"?
*/
int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)
{
struct commit_list *bases;
int ret = 0, i;
if (parse_commit(commit))
return ret;
for (i = 0; i < nr_reference; i++)
if (parse_commit(reference[i]))
return ret;
bases = paint_down_to_common(commit, nr_reference, reference);
if (commit->object.flags & PARENT2)
ret = 1;
clear_commit_marks(commit, all_flags);
for (i = 0; i < nr_reference; i++)
clear_commit_marks(reference[i], all_flags);
free_commit_list(bases);
return ret;
}
/*
* 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;
int ret = 0;
if (parse_commit(commit) || parse_commit(reference))
return ret;
bases = paint_down_to_common(commit, 1, &reference);
if (commit->object.flags & PARENT2)
ret = 1;
clear_commit_marks(commit, all_flags);
clear_commit_marks(reference, all_flags);
free_commit_list(bases);
return ret;
return in_merge_bases_many(commit, 1, &reference);
}
struct commit_list *reduce_heads(struct commit_list *heads)

View File

@ -171,6 +171,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
int is_descendant_of(struct commit *, struct commit_list *);
int in_merge_bases(struct commit *, struct commit *);
int in_merge_bases_many(struct commit *, int, 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,