From: Matthieu Moy <Matthieu.Moy@grenoble-inp•fr>
To: "René Scharfe" <l.s.r@web•de>
Cc: Jeff King <peff@peff•net>, Git List <git@vger•kernel.org>,
Junio C Hamano <gitster@pobox•com>,
Duy Nguyen <pclouds@gmail•com>
Subject: Re: [PATCH v2] wt-status: correct and simplify check for detached HEAD
Date: Wed, 25 Nov 2015 17:21:04 +0100 [thread overview]
Message-ID: <vpqvb8qt5hr.fsf@anie.imag.fr> (raw)
In-Reply-To: <5655C14A.1060308@web.de> ("René Scharfe"'s message of "Wed, 25 Nov 2015 15:10:18 +0100")
René Scharfe <l.s.r@web•de> writes:
> 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;
> }
Indeed, the code is much simpler like this than with the previous
attempts. Looks all right to me.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
next prev parent reply other threads:[~2015-11-25 16:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-06 22:47 [PATCH] wt-status: use strncmp() for length-limited string comparison René Scharfe
2015-11-24 21:36 ` Jeff King
2015-11-25 2:16 ` René Scharfe
2015-11-25 9:15 ` Jeff King
2015-11-25 10:29 ` Matthieu Moy
2015-11-25 14:10 ` [PATCH v2] wt-status: correct and simplify check for detached HEAD René Scharfe
2015-11-25 16:21 ` Matthieu Moy [this message]
2015-11-28 17:31 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=vpqvb8qt5hr.fsf@anie.imag.fr \
--to=matthieu.moy@grenoble-inp$(echo .)fr \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=l.s.r@web$(echo .)de \
--cc=pclouds@gmail$(echo .)com \
--cc=peff@peff$(echo .)net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox