Skip to content

Commit 4d0069f

Browse files
committed
Merge branch 'rs/status-detached-head-memcmp' into maint
Fix some string-matching corner cases when digging in the reflog for "git status". * rs/status-detached-head-memcmp: wt-status: correct and simplify check for detached HEAD
2 parents b5d2d8e + 904de44 commit 4d0069f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

wt-status.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,15 +1317,14 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
13171317
target += strlen(" to ");
13181318
strbuf_reset(&cb->buf);
13191319
hashcpy(cb->nsha1, nsha1);
1320-
for (end = target; *end && *end != '\n'; end++)
1321-
;
1322-
if (!memcmp(target, "HEAD", end - target)) {
1320+
end = strchrnul(target, '\n');
1321+
strbuf_add(&cb->buf, target, end - target);
1322+
if (!strcmp(cb->buf.buf, "HEAD")) {
13231323
/* HEAD is relative. Resolve it to the right reflog entry. */
1324+
strbuf_reset(&cb->buf);
13241325
strbuf_addstr(&cb->buf,
13251326
find_unique_abbrev(nsha1, DEFAULT_ABBREV));
1326-
return 1;
13271327
}
1328-
strbuf_add(&cb->buf, target, end - target);
13291328
return 1;
13301329
}
13311330

0 commit comments

Comments
 (0)