Skip to content

Commit 7fcdb36

Browse files
Jake Gouldinggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 269defd commit 7fcdb36

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

builtin-branch.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,6 @@ struct ref_list {
193193
int kinds;
194194
};
195195

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-
211196
static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
212197
{
213198
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,
231216
return error("branch '%s' does not point at a commit", refname);
232217

233218
/* 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))
235220
return 0;
236221

237222
/* 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
401386
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
402387

403388
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)) {
405391
struct ref_item item;
406392
item.name = xstrdup("(no branch)");
407393
item.kind = REF_LOCAL_BRANCH;

commit.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,21 @@ struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
705705
return get_merge_bases_many(one, 1, &two, cleanup);
706706
}
707707

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+
708723
int in_merge_bases(struct commit *commit, struct commit **reference, int num)
709724
{
710725
struct commit_list *bases, *b;

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ extern int is_repository_shallow(void);
133133
extern struct commit_list *get_shallow_commits(struct object_array *heads,
134134
int depth, int shallow_flag, int not_shallow_flag);
135135

136+
int is_descendant_of(struct commit *, struct commit_list *);
136137
int in_merge_bases(struct commit *, struct commit **, int);
137138

138139
extern int interactive_add(int argc, const char **argv, const char *prefix);

0 commit comments

Comments
 (0)