Skip to content

Commit 2ecd2bb

Browse files
author
Junio C Hamano
committed
Move in_merge_bases() to commit.c
This reasonably useful function was hidden inside builtin-branch.c
1 parent e29cb53 commit 2ecd2bb

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

builtin-branch.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,6 @@ const char *branch_get_color(enum color_branch ix)
7474
return "";
7575
}
7676

77-
static int in_merge_bases(const unsigned char *sha1,
78-
struct commit *rev1,
79-
struct commit *rev2)
80-
{
81-
struct commit_list *bases, *b;
82-
int ret = 0;
83-
84-
bases = get_merge_bases(rev1, rev2, 1);
85-
for (b = bases; b; b = b->next) {
86-
if (!hashcmp(sha1, b->item->object.sha1)) {
87-
ret = 1;
88-
break;
89-
}
90-
}
91-
92-
free_commit_list(bases);
93-
return ret;
94-
}
95-
9677
static int delete_branches(int argc, const char **argv, int force, int kinds)
9778
{
9879
struct commit *rev, *head_rev = head_rev;
@@ -153,7 +134,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
153134
*/
154135

155136
if (!force &&
156-
!in_merge_bases(sha1, rev, head_rev)) {
137+
!in_merge_bases(rev, head_rev)) {
157138
error("The branch '%s' is not a strict subset of "
158139
"your current HEAD.\n"
159140
"If you are sure you want to delete it, "

commit.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,3 +1009,20 @@ struct commit_list *get_merge_bases(struct commit *one,
10091009
free(rslt);
10101010
return result;
10111011
}
1012+
1013+
int in_merge_bases(struct commit *rev1, struct commit *rev2)
1014+
{
1015+
struct commit_list *bases, *b;
1016+
int ret = 0;
1017+
1018+
bases = get_merge_bases(rev1, rev2, 1);
1019+
for (b = bases; b; b = b->next) {
1020+
if (!hashcmp(rev1->object.sha1, b->item->object.sha1)) {
1021+
ret = 1;
1022+
break;
1023+
}
1024+
}
1025+
1026+
free_commit_list(bases);
1027+
return ret;
1028+
}

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ int read_graft_file(const char *graft_file);
107107

108108
extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
109109

110+
int in_merge_bases(struct commit *rev1, struct commit *rev2);
110111
#endif /* COMMIT_H */

0 commit comments

Comments
 (0)