resolve_ref_unsafe(): handle the case of an SHA-1 within loop
There is only one "break" statement within the loop, which jumps to the code after the loop that handles the case of a file that holds a SHA-1. So move that code from below the loop into the if statement where the break was previously located. This makes the logic flow more local. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jun 19, 2013 at 08:36 UTC
2884c06ae78e569a513701c2d43f4ed79bd252ce
1 file changed
+13
-9
refs.c
+13
-9
@@ -1300,8 +1300,19 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
1300
/*
1301
* Is it a symbolic ref?
1302
*/
1303
- if (prefixcmp(buffer, "ref:"))
1304
- break;
1303
+ if (prefixcmp(buffer, "ref:")) {
1304
+ /*
1305
+ * Please note that FETCH_HEAD has a second
1306
+ * line containing other data.
1307
+ */
1308
+ if (get_sha1_hex(buffer, sha1) ||
1309
+ (buffer[40] != '\0' && !isspace(buffer[40]))) {
1310
+ if (flag)
1311
+ *flag |= REF_ISBROKEN;
1312
+ return NULL;
1313
+ }
1314
+ return refname;
1315
+ }
1316
if (flag)
1317
*flag |= REF_ISSYMREF;
1318
buf = buffer + 4;
@@ -1314,13 +1325,6 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
1325
}
1326
refname = strcpy(refname_buffer, buf);
1327
}
1317
- /* Please note that FETCH_HEAD has a second line containing other data. */
1318
- if (get_sha1_hex(buffer, sha1) || (buffer[40] != '\0' && !isspace(buffer[40]))) {
1319
- if (flag)
1320
- *flag |= REF_ISBROKEN;
1321
- return NULL;
1322
- }
1323
- return refname;
1328
}
1329
1330
char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag)