summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-12-08 22:11:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-12-08 22:11:32 (GMT)
commit4d0069f27717c801569e6f8a94ce00cf04f7bcd0 (patch)
treefa01ec0b80d59ac9fd4dbcdd2da115c6b98d78c1
parentb5d2d8eef0ad08022a3f635c0bc292eb2cc5aefc (diff)
parent904de44c1c2eb099c5696ad9d74e0e15cc57b55e (diff)
downloadgit-4d0069f27717c801569e6f8a94ce00cf04f7bcd0.zip
git-4d0069f27717c801569e6f8a94ce00cf04f7bcd0.tar.gz
git-4d0069f27717c801569e6f8a94ce00cf04f7bcd0.tar.bz2
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
-rw-r--r--wt-status.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/wt-status.c b/wt-status.c
index 435fc28..ced53dd 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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;
}