@matheusbsbs / matheus-bagliano / commits / 7fcdb36e29
Fork 0

Make has_commit() non-static

Move has_commit() from branch to a common location, in preparation for using it in "git-tag". Rename it to is_descendant_of() to make it more unique and descriptive. Signed-off-by: Jake Goulding <goulding@vivisimo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jake Goulding committed Jan 26, 2009 at 09:13 UTC 7fcdb36e29f9a5e779bc9e44cd69f8f69fac9426
3 files changed +19 -17
builtin-branch.c
+3 -17
@@ -193,21 +193,6 @@ struct ref_list {
193 int kinds;
194 };
195
196 -static int has_commit(struct commit *commit, struct commit_list *with_commit)
197 -{
198 - if (!with_commit)
199 - return 1;
200 - while (with_commit) {
201 - struct commit *other;
202 -
203 - other = with_commit->item;
204 - with_commit = with_commit->next;
205 - if (in_merge_bases(other, &commit, 1))
206 - return 1;
207 - }
208 - return 0;
209 -}
210 -
196 static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
197 {
198 struct ref_list *ref_list = (struct ref_list*)(cb_data);
@@ -231,7 +216,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
216 return error("branch '%s' does not point at a commit", refname);
217
218 /* Filter with with_commit if specified */
234 - if (!has_commit(commit, ref_list->with_commit))
219 + if (!is_descendant_of(commit, ref_list->with_commit))
220 return 0;
221
222 /* Don't add types the caller doesn't want */
@@ -401,7 +386,8 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
386 qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
387
388 detached = (detached && (kinds & REF_LOCAL_BRANCH));
404 - if (detached && head_commit && has_commit(head_commit, with_commit)) {
389 + if (detached && head_commit &&
390 + is_descendant_of(head_commit, with_commit)) {
391 struct ref_item item;
392 item.name = xstrdup("(no branch)");
393 item.kind = REF_LOCAL_BRANCH;
commit.c
+15
@@ -705,6 +705,21 @@ struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
705 return get_merge_bases_many(one, 1, &two, cleanup);
706 }
707
708 +int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
709 +{
710 + if (!with_commit)
711 + return 1;
712 + while (with_commit) {
713 + struct commit *other;
714 +
715 + other = with_commit->item;
716 + with_commit = with_commit->next;
717 + if (in_merge_bases(other, &commit, 1))
718 + return 1;
719 + }
720 + return 0;
721 +}
722 +
723 int in_merge_bases(struct commit *commit, struct commit **reference, int num)
724 {
725 struct commit_list *bases, *b;
commit.h
+1
@@ -133,6 +133,7 @@ extern int is_repository_shallow(void);
133 extern struct commit_list *get_shallow_commits(struct object_array *heads,
134 int depth, int shallow_flag, int not_shallow_flag);
135
136 +int is_descendant_of(struct commit *, struct commit_list *);
137 int in_merge_bases(struct commit *, struct commit **, int);
138
139 extern int interactive_add(int argc, const char **argv, const char *prefix);