git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Carlos Martín Nieto" <cmn@elego.de>
To: Jeff King <peff@peff.net>
Cc: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>,
	"git discussion list" <git@vger.kernel.org>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: Re: [PATCH] archive: simplify refname handling
Date: Fri, 18 May 2012 18:44:43 +0200	[thread overview]
Message-ID: <1337359483.3083.2.camel@centaur.lab.cmartin.tk> (raw)
In-Reply-To: <20120518155903.GA21264@sigill.intra.peff.net>

On Fri, 2012-05-18 at 11:59 -0400, Jeff King wrote:
> [+cc Carlos, as this is his code]
> 
> On Fri, May 18, 2012 at 07:15:17AM +0200, René Scharfe wrote:
> 
> > There is no need to build a copy of the relevant part of the string just
> > to make sure we have a NUL-terminated string.  We can simply pass the
> > length of the interesting part to dwim_ref() instead.
> > 
> > Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
> > ---
> >  archive.c |   17 +++++------------
> >  1 file changed, 5 insertions(+), 12 deletions(-)
> > 
> > diff --git a/archive.c b/archive.c
> > index cd083ea..ecc1ff0 100644
> > --- a/archive.c
> > +++ b/archive.c
> > @@ -254,18 +254,11 @@ static void parse_treeish_arg(const char **argv,
> >  	/* Remotes are only allowed to fetch actual refs */
> >  	if (remote) {
> >  		char *ref = NULL;
> > -		const char *refname, *colon = NULL;
> > -
> > -		colon = strchr(name, ':');
> > -		if (colon)
> > -			refname = xstrndup(name, colon - name);
> > -		else
> > -			refname = name;
> > -
> > -		if (!dwim_ref(refname, strlen(refname), sha1, &ref))
> > -			die("no such ref: %s", refname);
> > -		if (refname != name)
> > -			free((void *)refname);
> > +		const char *colon = strchr(name, ':');
> > +		size_t refnamelen = colon ? colon - name : strlen(name);
> > +
> > +		if (!dwim_ref(name, refnamelen, sha1, &ref))
> > +			die("no such ref: %.*s", refnamelen, name);
> >  		free(ref);
> 
> Looks obviously correct to me.

Yep, that's clearly a much better way of doing it.

   cmn

  reply	other threads:[~2012-05-18 16:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-18  5:15 [PATCH] archive: simplify refname handling René Scharfe
2012-05-18 15:59 ` Jeff King
2012-05-18 16:44   ` Carlos Martín Nieto [this message]
2012-05-18 18:22 ` Junio C Hamano
2012-05-18 18:27 ` Junio C Hamano

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=1337359483.3083.2.camel@centaur.lab.cmartin.tk \
    --to=cmn@elego.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=rene.scharfe@lsrfire.ath.cx \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).