git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] refs.c: use skip_prefix() in prettify_refname()

From
Stefan Beller <sbeller@google.com>
Date
Mar 23, 2017, 19:31 UTC
Message-ID
<CAGZ79kZ-yP=6bKnDg8zKjebDkDdQ4ZEur0sC+CCcv5OTdEC3RA@mail.gmail.com>
In-Reply-To
<20170323192313.ytr56pjpnillnh63@sigill.intra.peff.net>
On Thu, Mar 23, 2017 at 12:23 PM, Jeff King <peff@peff.net> wrote:
Show 32 quoted lines
> 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.
You do not need a conditional to short circuit things.
|| works outside an if, too. ;)

Anyway, maybe it's worth spelling it out with an if .. else if cascade for readability?

After your comment of short-circuiting this code is pretty clear, so maybe just a small comment would do?

Thanks, Stefan

>
> -Peff
Previous: Jeff KingNext: Junio C Hamano
Message 4 of 11 in “refs.c: use skip_prefix() in prettify_refname()”
  1. refs.c: use skip_prefix() in prettify_refname()SZEDER Gábor, Mar 23, 2017
  2. René ScharfeMar 23, 2017
  3. Jeff KingMar 23, 2017
  4. Stefan BellerMar 23, 2017
  5. Junio C HamanoMar 23, 2017
  6. René ScharfeMar 23, 2017
  7. Junio C HamanoMar 23, 2017
  8. Jeff KingMar 23, 2017
  9. Junio C HamanoMar 23, 2017
  10. SZEDER GáborMar 23, 2017
  11. René ScharfeMar 23, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.