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>
René Scharfe committed
May 18, 2012 at 07:15 UTC
c51a351a6bcc64ad8cb2ed5a6ebde54b8d50eef1
1 file changed
+5
-12
archive.c
+5
-12
@@ -260,18 +260,11 @@ static void parse_treeish_arg(const char **argv,
260
/* Remotes are only allowed to fetch actual refs */
261
if (remote) {
262
char *ref = NULL;
263
- const char *refname, *colon = NULL;
264
-
265
- colon = strchr(name, ':');
266
- if (colon)
267
- refname = xstrndup(name, colon - name);
268
- else
269
- refname = name;
270
-
271
- if (!dwim_ref(refname, strlen(refname), sha1, &ref))
272
- die("no such ref: %s", refname);
273
- if (refname != name)
274
- free((void *)refname);
263
+ const char *colon = strchr(name, ':');
264
+ int refnamelen = colon ? colon - name : strlen(name);
265
+
266
+ if (!dwim_ref(name, refnamelen, sha1, &ref))
267
+ die("no such ref: %.*s", refnamelen, name);
268
free(ref);
269
}
270