summaryrefslogtreecommitdiff
path: root/archive.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2012-05-18 05:15:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-05-18 18:26:10 (GMT)
commitc51a351a6bcc64ad8cb2ed5a6ebde54b8d50eef1 (patch)
tree2dba4441dbdf527c5a37c8c071c63a1f349f1ff5 /archive.c
parentd0f1ea6003d97e63110fa7d50bb07f546a909b6e (diff)
downloadgit-c51a351a6bcc64ad8cb2ed5a6ebde54b8d50eef1.zip
git-c51a351a6bcc64ad8cb2ed5a6ebde54b8d50eef1.tar.gz
git-c51a351a6bcc64ad8cb2ed5a6ebde54b8d50eef1.tar.bz2
archive: simplify refname handling
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>
Diffstat (limited to 'archive.c')
-rw-r--r--archive.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/archive.c b/archive.c
index 1ee837d..1e7156d 100644
--- 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);
}