From: "Shawn O. Pearce" <spearce@spearce.org>
To: SZEDER GGGbor <szeder@ira.uka.de>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [RFC/PATCH 1/2] for-each-ref: add new format 'refbasename'
Date: Fri, 29 Aug 2008 07:34:48 -0700 [thread overview]
Message-ID: <20080829143448.GC7403@spearce.org> (raw)
In-Reply-To: <0329f1ab2642e1dab701b5fc6517bfb1b4ea2d46.1220004755.git.szeder@ira.uka.de>
SZEDER GGGbor <szeder@ira.uka.de> wrote:
> Therefore, we introduce a new for-each-ref format called 'refbasename',
> which strips everything before and including the second '/' in the ref's
> name from the output.
>
> I assumed that refs always look like 'refs/{heads,tags,whatever}/foo',
> hence this patch breaks if a ref might look like 'refs/foo' or just
> 'foo'. But can I really rely on that?
>
> diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
> index 21e92bb..1993ff4 100644
> --- a/builtin-for-each-ref.c
> +++ b/builtin-for-each-ref.c
> @@ -577,6 +578,10 @@ static void populate_value(struct refinfo *ref)
> char *s = xmalloc(len + 4);
> sprintf(s, "%s^{}", ref->refname);
> v->s = s;
> + } else if (!strcmp(name, "refbasename")) {
> + char * p = strchr(ref->refname, '/');
> + p = strchr(p+1, '/');
> + v->s = p+1;
Please be careful here and check for !p. A refname may be missing
one or two '/' in which case you will cause the process to segfault.
I don't think its a good idea to assume you'll always have to '/'
in the name. "refs/foo" can be created by git-update-ref. Or if
we ever started to report on HEAD this output tag would crash.
Also, as a style nit, its "p + 1" not "p+1".
Test cases?
On the other hand, I like where this is going. Given that it
has such a nice effect on the bash completion for larger repos
I'd like to see it in Git.
--
Shawn.
next prev parent reply other threads:[~2008-08-29 14:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-29 10:37 [RFC/PATCH 1/2] for-each-ref: add new format 'refbasename' SZEDER Gábor
2008-08-29 10:37 ` [RFC/PATCH 2/2] bash: use for-each-ref " SZEDER Gábor
2008-08-29 14:34 ` Shawn O. Pearce [this message]
2008-08-29 16:45 ` [RFC/PATCH 1/2 v2] for-each-ref: add new " SZEDER Gábor
2008-08-29 18:21 ` [RFC/PATCH 1/2] " Bert Wesarg
2008-08-29 21:41 ` [PATCH] for-each-ref: new 'refshort' format Bert Wesarg
2008-08-31 4:31 ` Junio C Hamano
2008-08-31 7:11 ` Bert Wesarg
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=20080829143448.GC7403@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=szeder@ira.uka.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.