The last statement of the loop body is "break", so this doesn't change the logical flow...yet. Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx> --- This commit is 98% whitespace changes, so do it in a separate commit to make the changes in the next commit more obvious. refs.c | 123 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 64 insertions(+), 59 deletions(-) diff --git a/refs.c b/refs.c index 2722f75..7a77d76 100644 --- a/refs.c +++ b/refs.c @@ -1248,77 +1248,82 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea git_snpath(path, sizeof(path), "%s", refname); - if (lstat(path, &st) < 0) { - if (errno == ENOENT) - return handle_missing_loose_ref(refname, sha1, reading, flag); - else - return NULL; - } + for (;;) { + if (lstat(path, &st) < 0) { + if (errno == ENOENT) + return handle_missing_loose_ref( + refname, sha1, + reading, flag); + else + return NULL; + } - /* Follow "normalized" - ie "refs/.." symlinks by hand */ - if (S_ISLNK(st.st_mode)) { - len = readlink(path, buffer, sizeof(buffer)-1); - if (len < 0) - return NULL; - buffer[len] = 0; - if (!prefixcmp(buffer, "refs/") && - !check_refname_format(buffer, 0)) { - strcpy(refname_buffer, buffer); - refname = refname_buffer; - if (flag) - *flag |= REF_ISSYMREF; - continue; + /* Follow "normalized" - ie "refs/.." symlinks by hand */ + if (S_ISLNK(st.st_mode)) { + len = readlink(path, buffer, sizeof(buffer)-1); + if (len < 0) + return NULL; + buffer[len] = 0; + if (!prefixcmp(buffer, "refs/") && + !check_refname_format(buffer, 0)) { + strcpy(refname_buffer, buffer); + refname = refname_buffer; + if (flag) + *flag |= REF_ISSYMREF; + break; + } } - } - /* Is it a directory? */ - if (S_ISDIR(st.st_mode)) { - errno = EISDIR; - return NULL; - } + /* Is it a directory? */ + if (S_ISDIR(st.st_mode)) { + errno = EISDIR; + return NULL; + } - /* - * Anything else, just open it and try to use it as - * a ref - */ - fd = open(path, O_RDONLY); - if (fd < 0) - return NULL; - len = read_in_full(fd, buffer, sizeof(buffer)-1); - close(fd); - if (len < 0) - return NULL; - while (len && isspace(buffer[len-1])) - len--; - buffer[len] = '\0'; + /* + * Anything else, just open it and try to use it as + * a ref + */ + fd = open(path, O_RDONLY); + if (fd < 0) + return NULL; + len = read_in_full(fd, buffer, sizeof(buffer)-1); + close(fd); + if (len < 0) + return NULL; + while (len && isspace(buffer[len-1])) + len--; + buffer[len] = '\0'; - /* - * Is it a symbolic ref? - */ - if (prefixcmp(buffer, "ref:")) { /* - * Please note that FETCH_HEAD has a second - * line containing other data. + * Is it a symbolic ref? */ - if (get_sha1_hex(buffer, sha1) || - (buffer[40] != '\0' && !isspace(buffer[40]))) { + if (prefixcmp(buffer, "ref:")) { + /* + * Please note that FETCH_HEAD has a second + * line containing other data. + */ + if (get_sha1_hex(buffer, sha1) || + (buffer[40] != '\0' && !isspace(buffer[40]))) { + if (flag) + *flag |= REF_ISBROKEN; + return NULL; + } + return refname; + } + if (flag) + *flag |= REF_ISSYMREF; + buf = buffer + 4; + while (isspace(*buf)) + buf++; + if (check_refname_format(buf, REFNAME_ALLOW_ONELEVEL)) { if (flag) *flag |= REF_ISBROKEN; return NULL; } - return refname; - } - if (flag) - *flag |= REF_ISSYMREF; - buf = buffer + 4; - while (isspace(*buf)) - buf++; - if (check_refname_format(buf, REFNAME_ALLOW_ONELEVEL)) { - if (flag) - *flag |= REF_ISBROKEN; - return NULL; + refname = strcpy(refname_buffer, buf); + break; } - refname = strcpy(refname_buffer, buf); } } -- 1.8.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html