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>
This commit is contained in:
parent
d0f1ea6003
commit
c51a351a6b
15
archive.c
15
archive.c
@ -260,18 +260,11 @@ static void parse_treeish_arg(const char **argv,
|
|||||||
/* Remotes are only allowed to fetch actual refs */
|
/* Remotes are only allowed to fetch actual refs */
|
||||||
if (remote) {
|
if (remote) {
|
||||||
char *ref = NULL;
|
char *ref = NULL;
|
||||||
const char *refname, *colon = NULL;
|
const char *colon = strchr(name, ':');
|
||||||
|
int refnamelen = colon ? colon - name : strlen(name);
|
||||||
|
|
||||||
colon = strchr(name, ':');
|
if (!dwim_ref(name, refnamelen, sha1, &ref))
|
||||||
if (colon)
|
die("no such ref: %.*s", refnamelen, name);
|
||||||
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);
|
|
||||||
free(ref);
|
free(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user