Skip to content

Commit

Permalink
archive: simplify refname handling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed May 18, 2012
1 parent d0f1ea6 commit c51a351
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit c51a351

Please sign in to comment.