Skip to content

Commit 2884c06

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 47f534b commit 2884c06

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

refs.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,19 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
13001300
/*
13011301
* Is it a symbolic ref?
13021302
*/
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+
}
13051316
if (flag)
13061317
*flag |= REF_ISSYMREF;
13071318
buf = buffer + 4;
@@ -1314,13 +1325,6 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
13141325
}
13151326
refname = strcpy(refname_buffer, buf);
13161327
}
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;
13241328
}
13251329

13261330
char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag)

0 commit comments

Comments
 (0)