Skip to content

Commit f5d0e16

Browse files
René Scharfegitster
authored andcommitted
branch: factor out check_branch_commit()
Move the code to perform checks on the tip commit of a branch to its own function. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87a5461 commit f5d0e16

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

builtin/branch.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,28 @@ static int branch_merged(int kind, const char *name,
154154
return merged;
155155
}
156156

157+
static int check_branch_commit(const char *branchname, const char *refname,
158+
unsigned char *sha1, struct commit *head_rev,
159+
int kinds, int force)
160+
{
161+
struct commit *rev = lookup_commit_reference(sha1);
162+
if (!rev) {
163+
error(_("Couldn't look up commit object for '%s'"), refname);
164+
return -1;
165+
}
166+
if (!force && !branch_merged(kinds, branchname, rev, head_rev)) {
167+
error(_("The branch '%s' is not fully merged.\n"
168+
"If you are sure you want to delete it, "
169+
"run 'git branch -D %s'."), branchname, branchname);
170+
return -1;
171+
}
172+
return 0;
173+
}
174+
157175
static int delete_branches(int argc, const char **argv, int force, int kinds,
158176
int quiet)
159177
{
160-
struct commit *rev, *head_rev = NULL;
178+
struct commit *head_rev = NULL;
161179
unsigned char sha1[20];
162180
char *name = NULL;
163181
const char *fmt;
@@ -206,17 +224,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
206224
continue;
207225
}
208226

209-
rev = lookup_commit_reference(sha1);
210-
if (!rev) {
211-
error(_("Couldn't look up commit object for '%s'"), name);
212-
ret = 1;
213-
continue;
214-
}
215-
216-
if (!force && !branch_merged(kinds, bname.buf, rev, head_rev)) {
217-
error(_("The branch '%s' is not fully merged.\n"
218-
"If you are sure you want to delete it, "
219-
"run 'git branch -D %s'."), bname.buf, bname.buf);
227+
if (check_branch_commit(bname.buf, name, sha1, head_rev, kinds,
228+
force)) {
220229
ret = 1;
221230
continue;
222231
}

0 commit comments

Comments
 (0)