git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: git discussion list <git@vger.kernel.org>
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] archive: simplify refname handling
Date: Fri, 18 May 2012 07:15:17 +0200	[thread overview]
Message-ID: <4FB5DAE5.6020307@lsrfire.ath.cx> (raw)

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);
 	}
 
-- 
1.7.10.2

             reply	other threads:[~2012-05-18  5:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-18  5:15 René Scharfe [this message]
2012-05-18 15:59 ` [PATCH] archive: simplify refname handling Jeff King
2012-05-18 16:44   ` Carlos Martín Nieto
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=4FB5DAE5.6020307@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).