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>
Junio C Hamano committed
Mar 4, 2013 at 10:16 UTC
4c4b27e8cefdd88d76590c5fd786d1d43fb6f898
2 files changed
+19
-6
commit.c
+18
-6
@@ -859,25 +859,37 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
859
}
860
861
/*
862
- * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
862
+ * Is "commit" an ancestor of one of the "references"?
863
*/
864
-int in_merge_bases(struct commit *commit, struct commit *reference)
864
+int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)
865
{
866
struct commit_list *bases;
867
- int ret = 0;
867
+ int ret = 0, i;
868
869
- if (parse_commit(commit) || parse_commit(reference))
869
+ if (parse_commit(commit))
870
return ret;
871
+ for (i = 0; i < nr_reference; i++)
872
+ if (parse_commit(reference[i]))
873
+ return ret;
874
872
- bases = paint_down_to_common(commit, 1, &reference);
875
+ bases = paint_down_to_common(commit, nr_reference, reference);
876
if (commit->object.flags & PARENT2)
877
ret = 1;
878
clear_commit_marks(commit, all_flags);
876
- clear_commit_marks(reference, all_flags);
879
+ for (i = 0; i < nr_reference; i++)
880
+ clear_commit_marks(reference[i], all_flags);
881
free_commit_list(bases);
882
return ret;
883
}
884
885
+/*
886
+ * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
887
+ */
888
+int in_merge_bases(struct commit *commit, struct commit *reference)
889
+{
890
+ return in_merge_bases_many(commit, 1, &reference);
891
+}
892
+
893
struct commit_list *reduce_heads(struct commit_list *heads)
894
{
895
struct commit_list *p;
commit.h
+1
@@ -171,6 +171,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
171
172
int is_descendant_of(struct commit *, struct commit_list *);
173
int in_merge_bases(struct commit *, struct commit *);
174
+int in_merge_bases_many(struct commit *, int, struct commit **);
175
176
extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
177
extern int run_add_interactive(const char *revision, const char *patch_mode,