archive: simplify refname handling
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Fri, 18 May 2012 05:15:17 +0000 (07:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 May 2012 18:26:10 +0000 (11:26 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive.c

index 1ee837d7170cfa52da6725cfe7c5ae0d6d67462e..1e7156d580256db9f5033f858ea7d408ec182f44 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -260,18 +260,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, ':');
+               int refnamelen = colon ? colon - name : strlen(name);
+
+               if (!dwim_ref(name, refnamelen, sha1, &ref))
+                       die("no such ref: %.*s", refnamelen, name);
                free(ref);
        }