Skip to content

Commit 33aef83

Browse files
sunshinecogitster
authored andcommitted
checkout: check_linked_checkout: simplify symref parsing
check_linked_checkout() only understands symref-style HEAD (i.e. "ref: refs/heads/master"), however, HEAD may also be a an actual symbolic link (on platforms which support it), thus it will need to check that style HEAD, as well (via readlink()). As a preparatory step, simplify parsing of symref-style HEAD so the actual branch check can be re-used easily for symbolic links (in an upcoming patch). Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39e69e1 commit 33aef83

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

builtin/checkout.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,6 @@ static void check_linked_checkout(const char *branch, const char *id)
878878
struct strbuf sb = STRBUF_INIT;
879879
struct strbuf path = STRBUF_INIT;
880880
struct strbuf gitdir = STRBUF_INIT;
881-
const char *start, *end;
882881

883882
/*
884883
* $GIT_COMMON_DIR/HEAD is practically outside
@@ -890,15 +889,13 @@ static void check_linked_checkout(const char *branch, const char *id)
890889
else
891890
strbuf_addf(&path, "%s/HEAD", get_git_common_dir());
892891

893-
if (strbuf_read_file(&sb, path.buf, 0) < 0 ||
894-
!skip_prefix(sb.buf, "ref:", &start))
892+
if (strbuf_read_file(&sb, path.buf, 0) >= 0 &&
893+
starts_with(sb.buf, "ref:")) {
894+
strbuf_remove(&sb, 0, strlen("ref:"));
895+
strbuf_trim(&sb);
896+
} else
895897
goto done;
896-
while (isspace(*start))
897-
start++;
898-
end = start;
899-
while (*end && !isspace(*end))
900-
end++;
901-
if (strncmp(start, branch, end - start) || branch[end - start] != '\0')
898+
if (strcmp(sb.buf, branch))
902899
goto done;
903900
if (id) {
904901
strbuf_reset(&path);

0 commit comments

Comments
 (0)