git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] archive: simplify refname handling

From
Jeff King <peff@peff.net>
Date
May 18, 2012, 15:59 UTC
Message-ID
<20120518155903.GA21264@sigill.intra.peff.net>
In-Reply-To
<4FB5DAE5.6020307@lsrfire.ath.cx>
[+cc Carlos, as this is his code]
On Fri, May 18, 2012 at 07:15:17AM +0200, René Scharfe wrote:
Show 35 quoted lines
> 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>
> ---
>  archive.c |   17 +++++------------
>  1 file changed, 5 insertions(+), 12 deletions(-)
> 
> diff --git a/archive.c b/archive.c
> index cd083ea..ecc1ff0 100644
> --- a/archive.c
> +++ b/archive.c
> @@ -254,18 +254,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, ':');
> +		size_t refnamelen = colon ? colon - name : strlen(name);
> +
> +		if (!dwim_ref(name, refnamelen, sha1, &ref))
> +			die("no such ref: %.*s", refnamelen, name);
>  		free(ref);
Looks obviously correct to me.
-Peff
Previous: René ScharfeNext: Carlos Martín Nieto
Message 2 of 5 in “archive: simplify refname handling”
  1. archive: simplify refname handlingRené Scharfe, May 18, 2012
  2. Jeff KingMay 18, 2012
  3. Carlos Martín NietoMay 18, 2012
  4. Junio C HamanoMay 18, 2012
  5. Junio C HamanoMay 18, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.