Skip to content

Commit

Permalink
Merge branch 'rs/status-detached-head-memcmp' into maint
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Dec 8, 2015
2 parents b5d2d8e + 904de44 commit 4d0069f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,15 +1317,14 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
target += strlen(" to ");
strbuf_reset(&cb->buf);
hashcpy(cb->nsha1, nsha1);
for (end = target; *end && *end != '\n'; end++)
;
if (!memcmp(target, "HEAD", end - target)) {
end = strchrnul(target, '\n');
strbuf_add(&cb->buf, target, end - target);
if (!strcmp(cb->buf.buf, "HEAD")) {
/* HEAD is relative. Resolve it to the right reflog entry. */
strbuf_reset(&cb->buf);
strbuf_addstr(&cb->buf,
find_unique_abbrev(nsha1, DEFAULT_ABBREV));
return 1;
}
strbuf_add(&cb->buf, target, end - target);
return 1;
}

Expand Down

0 comments on commit 4d0069f

Please sign in to comment.