Move in_merge_bases() to commit.c
This reasonably useful function was hidden inside builtin-branch.c
This commit is contained in:
@ -74,25 +74,6 @@ const char *branch_get_color(enum color_branch ix)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static int in_merge_bases(const unsigned char *sha1,
|
|
||||||
struct commit *rev1,
|
|
||||||
struct commit *rev2)
|
|
||||||
{
|
|
||||||
struct commit_list *bases, *b;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
bases = get_merge_bases(rev1, rev2, 1);
|
|
||||||
for (b = bases; b; b = b->next) {
|
|
||||||
if (!hashcmp(sha1, b->item->object.sha1)) {
|
|
||||||
ret = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free_commit_list(bases);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int delete_branches(int argc, const char **argv, int force, int kinds)
|
static int delete_branches(int argc, const char **argv, int force, int kinds)
|
||||||
{
|
{
|
||||||
struct commit *rev, *head_rev = head_rev;
|
struct commit *rev, *head_rev = head_rev;
|
||||||
@ -153,7 +134,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (!force &&
|
if (!force &&
|
||||||
!in_merge_bases(sha1, rev, head_rev)) {
|
!in_merge_bases(rev, head_rev)) {
|
||||||
error("The branch '%s' is not a strict subset of "
|
error("The branch '%s' is not a strict subset of "
|
||||||
"your current HEAD.\n"
|
"your current HEAD.\n"
|
||||||
"If you are sure you want to delete it, "
|
"If you are sure you want to delete it, "
|
||||||
|
17
commit.c
17
commit.c
@ -1009,3 +1009,20 @@ struct commit_list *get_merge_bases(struct commit *one,
|
|||||||
free(rslt);
|
free(rslt);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int in_merge_bases(struct commit *rev1, struct commit *rev2)
|
||||||
|
{
|
||||||
|
struct commit_list *bases, *b;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
bases = get_merge_bases(rev1, rev2, 1);
|
||||||
|
for (b = bases; b; b = b->next) {
|
||||||
|
if (!hashcmp(rev1->object.sha1, b->item->object.sha1)) {
|
||||||
|
ret = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free_commit_list(bases);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
1
commit.h
1
commit.h
@ -107,4 +107,5 @@ int read_graft_file(const char *graft_file);
|
|||||||
|
|
||||||
extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
|
extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
|
||||||
|
|
||||||
|
int in_merge_bases(struct commit *rev1, struct commit *rev2);
|
||||||
#endif /* COMMIT_H */
|
#endif /* COMMIT_H */
|
||||||
|
Reference in New Issue
Block a user