git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] archive: simplify refname handling
@ 2012-05-18  5:15 René Scharfe
  2012-05-18 15:59 ` Jeff King
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: René Scharfe @ 2012-05-18  5:15 UTC (permalink / raw)
  To: git discussion list; +Cc: Jeff King, Junio C Hamano

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-05-18 18:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2012-05-18 18:22 ` Junio C Hamano
2012-05-18 18:27 ` Junio C Hamano

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).