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>
This commit is contained in:
parent
269defdf30
commit
7fcdb36e29
@ -193,21 +193,6 @@ struct ref_list {
|
|||||||
int kinds;
|
int kinds;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int has_commit(struct commit *commit, struct commit_list *with_commit)
|
|
||||||
{
|
|
||||||
if (!with_commit)
|
|
||||||
return 1;
|
|
||||||
while (with_commit) {
|
|
||||||
struct commit *other;
|
|
||||||
|
|
||||||
other = with_commit->item;
|
|
||||||
with_commit = with_commit->next;
|
|
||||||
if (in_merge_bases(other, &commit, 1))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
|
static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
|
||||||
{
|
{
|
||||||
struct ref_list *ref_list = (struct ref_list*)(cb_data);
|
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,
|
|||||||
return error("branch '%s' does not point at a commit", refname);
|
return error("branch '%s' does not point at a commit", refname);
|
||||||
|
|
||||||
/* Filter with with_commit if specified */
|
/* Filter with with_commit if specified */
|
||||||
if (!has_commit(commit, ref_list->with_commit))
|
if (!is_descendant_of(commit, ref_list->with_commit))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Don't add types the caller doesn't want */
|
/* 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
|
|||||||
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
|
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
|
||||||
|
|
||||||
detached = (detached && (kinds & REF_LOCAL_BRANCH));
|
detached = (detached && (kinds & REF_LOCAL_BRANCH));
|
||||||
if (detached && head_commit && has_commit(head_commit, with_commit)) {
|
if (detached && head_commit &&
|
||||||
|
is_descendant_of(head_commit, with_commit)) {
|
||||||
struct ref_item item;
|
struct ref_item item;
|
||||||
item.name = xstrdup("(no branch)");
|
item.name = xstrdup("(no branch)");
|
||||||
item.kind = REF_LOCAL_BRANCH;
|
item.kind = REF_LOCAL_BRANCH;
|
||||||
|
15
commit.c
15
commit.c
@ -705,6 +705,21 @@ struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
|
|||||||
return get_merge_bases_many(one, 1, &two, cleanup);
|
return get_merge_bases_many(one, 1, &two, cleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
|
||||||
|
{
|
||||||
|
if (!with_commit)
|
||||||
|
return 1;
|
||||||
|
while (with_commit) {
|
||||||
|
struct commit *other;
|
||||||
|
|
||||||
|
other = with_commit->item;
|
||||||
|
with_commit = with_commit->next;
|
||||||
|
if (in_merge_bases(other, &commit, 1))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int in_merge_bases(struct commit *commit, struct commit **reference, int num)
|
int in_merge_bases(struct commit *commit, struct commit **reference, int num)
|
||||||
{
|
{
|
||||||
struct commit_list *bases, *b;
|
struct commit_list *bases, *b;
|
||||||
|
1
commit.h
1
commit.h
@ -133,6 +133,7 @@ extern int is_repository_shallow(void);
|
|||||||
extern struct commit_list *get_shallow_commits(struct object_array *heads,
|
extern struct commit_list *get_shallow_commits(struct object_array *heads,
|
||||||
int depth, int shallow_flag, int not_shallow_flag);
|
int depth, int shallow_flag, int not_shallow_flag);
|
||||||
|
|
||||||
|
int is_descendant_of(struct commit *, struct commit_list *);
|
||||||
int in_merge_bases(struct commit *, struct commit **, int);
|
int in_merge_bases(struct commit *, struct commit **, int);
|
||||||
|
|
||||||
extern int interactive_add(int argc, const char **argv, const char *prefix);
|
extern int interactive_add(int argc, const char **argv, const char *prefix);
|
||||||
|
Loading…
Reference in New Issue
Block a user