commit.c: add in_merge_bases_many()
authorJunio C Hamano <gitster@pobox.com>
Mon, 4 Mar 2013 18:16:42 +0000 (10:16 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Mar 2013 21:39:46 +0000 (13:39 -0800)
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>
commit.c
commit.h
index 4757e5058feae49d049a3742cbbfeaa3e9feb621..d12e7995cce18f4002bb4633467695a87850ba67 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -859,25 +859,37 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
 }
 
 /*
 }
 
 /*
- * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
+ * Is "commit" an ancestor of one of the "references"?
  */
  */
-int in_merge_bases(struct commit *commit, struct commit *reference)
+int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)
 {
        struct commit_list *bases;
 {
        struct commit_list *bases;
-       int ret = 0;
+       int ret = 0, i;
 
 
-       if (parse_commit(commit) || parse_commit(reference))
+       if (parse_commit(commit))
                return ret;
                return ret;
+       for (i = 0; i < nr_reference; i++)
+               if (parse_commit(reference[i]))
+                       return ret;
 
 
-       bases = paint_down_to_common(commit, 1, &reference);
+       bases = paint_down_to_common(commit, nr_reference, reference);
        if (commit->object.flags & PARENT2)
                ret = 1;
        clear_commit_marks(commit, all_flags);
        if (commit->object.flags & PARENT2)
                ret = 1;
        clear_commit_marks(commit, all_flags);
-       clear_commit_marks(reference, all_flags);
+       for (i = 0; i < nr_reference; i++)
+               clear_commit_marks(reference[i], all_flags);
        free_commit_list(bases);
        return ret;
 }
 
        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)
+{
+       return in_merge_bases_many(commit, 1, &reference);
+}
+
 struct commit_list *reduce_heads(struct commit_list *heads)
 {
        struct commit_list *p;
 struct commit_list *reduce_heads(struct commit_list *heads)
 {
        struct commit_list *p;
index b997eeaabd29509f76071eec5f9f9c4d3fc42e56..5057f141f047aa3ca448e2a329f12d2bd3f24019 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -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 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,
 
 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,