From: Junio C Hamano <gitster@pobox•com>
To: Jeff King <peff@peff•net>
Cc: "René Scharfe" <l.s.r@web•de>,
"SZEDER Gábor" <szeder.dev@gmail•com>,
git@vger•kernel.org
Subject: Re: [PATCH] refs.c: use skip_prefix() in prettify_refname()
Date: Thu, 23 Mar 2017 12:33:06 -0700 [thread overview]
Message-ID: <xmqqvaqzbxfx.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170323192313.ytr56pjpnillnh63@sigill.intra.peff.net> (Jeff King's message of "Thu, 23 Mar 2017 15:23:13 -0400")
Jeff King <peff@peff•net> writes:
> On Thu, Mar 23, 2017 at 08:18:26PM +0100, René Scharfe wrote:
>
>> Am 23.03.2017 um 16:50 schrieb SZEDER Gábor:
>> > This eliminates three magic numbers.
>> >
>> > Signed-off-by: SZEDER Gábor <szeder.dev@gmail•com>
>> > ---
>> > refs.c | 10 +++++-----
>> > 1 file changed, 5 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/refs.c b/refs.c
>> > index e7606716d..0272e332c 100644
>> > --- a/refs.c
>> > +++ b/refs.c
>> > @@ -366,11 +366,11 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
>> >
>> > const char *prettify_refname(const char *name)
>> > {
>> > - return name + (
>> > - starts_with(name, "refs/heads/") ? 11 :
>> > - starts_with(name, "refs/tags/") ? 10 :
>> > - starts_with(name, "refs/remotes/") ? 13 :
>> > - 0);
>> > + if (skip_prefix(name, "refs/heads/", &name) ||
>> > + skip_prefix(name, "refs/tags/", &name) ||
>> > + skip_prefix(name, "refs/remotes/", &name))
>> > + ; /* nothing */
>> > + return name;
>>
>> Nice, but why add the "if" when it's doing nothing?
>
> It's short-circuiting in the conditional.
I think René meant this:
/* just for side effects */
skip_prefix(name, "refs/heads/", &name) ||
skip_prefix(name, "refs/tags/", &name) ||
skip_prefix(name, "refs/remotes/", &name);
return name;
which still short-sircuits, even though I do think it looks
strange; "correct but strange".
next prev parent reply other threads:[~2017-03-23 19:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-23 15:50 [PATCH] refs.c: use skip_prefix() in prettify_refname() SZEDER Gábor
2017-03-23 19:18 ` René Scharfe
2017-03-23 19:23 ` Jeff King
2017-03-23 19:31 ` Stefan Beller
2017-03-23 19:33 ` Junio C Hamano [this message]
2017-03-23 19:36 ` René Scharfe
2017-03-23 19:40 ` Junio C Hamano
2017-03-23 19:39 ` Jeff King
2017-03-23 20:05 ` Junio C Hamano
2017-03-23 20:06 ` SZEDER Gábor
2017-03-23 20:06 ` René Scharfe
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=xmqqvaqzbxfx.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=l.s.r@web$(echo .)de \
--cc=peff@peff$(echo .)net \
--cc=szeder.dev@gmail$(echo .)com \
/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