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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 18, 2012 at 14:02 UTC
f5d0e162c49320d5069a63a05960fc5a38d72423
1 file changed
+21
-12
builtin/branch.c
+21
-12
@@ -154,10 +154,28 @@ static int branch_merged(int kind, const char *name,
154
return merged;
155
}
156
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
+
175
static int delete_branches(int argc, const char **argv, int force, int kinds,
176
int quiet)
177
{
160
- struct commit *rev, *head_rev = NULL;
178
+ struct commit *head_rev = NULL;
179
unsigned char sha1[20];
180
char *name = NULL;
181
const char *fmt;
@@ -206,17 +224,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
224
continue;
225
}
226
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)) {
229
ret = 1;
230
continue;
231
}