{"thread":{"id":"30550","subject":"[PATCH] archive: simplify refname handling","startedAt":"2012-05-18T05:15:17Z","lastAt":"2012-05-18T18:27:32Z","messageCount":5,"participants":["René Scharfe","Jeff King","Carlos Martín Nieto","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"191645","messageId":"4FB5DAE5.6020307@lsrfire.ath.cx","threadId":"30550","inReplyTo":null,"subject":"[PATCH] archive: simplify refname handling","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2012-05-18T05:15:17Z","receivedAt":"2012-05-18T05:15:17Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"There is no need to build a copy of the relevant part of the string just\nto make sure we have a NUL-terminated string.  We can simply pass the\nlength of the interesting part to dwim_ref() instead.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n archive.c |   17 +++++------------\n 1 file changed, 5 insertions(+), 12 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex cd083ea..ecc1ff0 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -254,18 +254,11 @@ static void parse_treeish_arg(const char **argv,\n \t/* Remotes are only allowed to fetch actual refs */\n \tif (remote) {\n \t\tchar *ref = NULL;\n-\t\tconst char *refname, *colon = NULL;\n-\n-\t\tcolon = strchr(name, ':');\n-\t\tif (colon)\n-\t\t\trefname = xstrndup(name, colon - name);\n-\t\telse\n-\t\t\trefname = name;\n-\n-\t\tif (!dwim_ref(refname, strlen(refname), sha1, &ref))\n-\t\t\tdie(\"no such ref: %s\", refname);\n-\t\tif (refname != name)\n-\t\t\tfree((void *)refname);\n+\t\tconst char *colon = strchr(name, ':');\n+\t\tsize_t refnamelen = colon ? colon - name : strlen(name);\n+\n+\t\tif (!dwim_ref(name, refnamelen, sha1, &ref))\n+\t\t\tdie(\"no such ref: %.*s\", refnamelen, name);\n \t\tfree(ref);\n \t}\n \n-- \n1.7.10.2\n"},{"id":"191667","messageId":"20120518155903.GA21264@sigill.intra.peff.net","threadId":"30550","inReplyTo":"4FB5DAE5.6020307@lsrfire.ath.cx","subject":"Re: [PATCH] archive: simplify refname handling","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-05-18T15:59:03Z","receivedAt":"2012-05-18T15:59:03Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"[+cc Carlos, as this is his code]\n\nOn Fri, May 18, 2012 at 07:15:17AM +0200, René Scharfe wrote:\n\n> There is no need to build a copy of the relevant part of the string just\n> to make sure we have a NUL-terminated string.  We can simply pass the\n> length of the interesting part to dwim_ref() instead.\n> \n> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n> ---\n>  archive.c |   17 +++++------------\n>  1 file changed, 5 insertions(+), 12 deletions(-)\n> \n> diff --git a/archive.c b/archive.c\n> index cd083ea..ecc1ff0 100644\n> --- a/archive.c\n> +++ b/archive.c\n> @@ -254,18 +254,11 @@ static void parse_treeish_arg(const char **argv,\n>  \t/* Remotes are only allowed to fetch actual refs */\n>  \tif (remote) {\n>  \t\tchar *ref = NULL;\n> -\t\tconst char *refname, *colon = NULL;\n> -\n> -\t\tcolon = strchr(name, ':');\n> -\t\tif (colon)\n> -\t\t\trefname = xstrndup(name, colon - name);\n> -\t\telse\n> -\t\t\trefname = name;\n> -\n> -\t\tif (!dwim_ref(refname, strlen(refname), sha1, &ref))\n> -\t\t\tdie(\"no such ref: %s\", refname);\n> -\t\tif (refname != name)\n> -\t\t\tfree((void *)refname);\n> +\t\tconst char *colon = strchr(name, ':');\n> +\t\tsize_t refnamelen = colon ? colon - name : strlen(name);\n> +\n> +\t\tif (!dwim_ref(name, refnamelen, sha1, &ref))\n> +\t\t\tdie(\"no such ref: %.*s\", refnamelen, name);\n>  \t\tfree(ref);\n\nLooks obviously correct to me.\n\n-Peff\n"},{"id":"191668","messageId":"1337359483.3083.2.camel@centaur.lab.cmartin.tk","threadId":"30550","inReplyTo":"20120518155903.GA21264@sigill.intra.peff.net","subject":"Re: [PATCH] archive: simplify refname handling","fromName":"Carlos Martín Nieto","fromEmail":"cmn@elego.de","sentAt":"2012-05-18T16:44:43Z","receivedAt":"2012-05-18T16:44:43Z","isPatch":true,"sender":{"key":"cmn@elego.de","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"On Fri, 2012-05-18 at 11:59 -0400, Jeff King wrote:\n> [+cc Carlos, as this is his code]\n> \n> On Fri, May 18, 2012 at 07:15:17AM +0200, René Scharfe wrote:\n> \n> > There is no need to build a copy of the relevant part of the string just\n> > to make sure we have a NUL-terminated string.  We can simply pass the\n> > length of the interesting part to dwim_ref() instead.\n> > \n> > Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n> > ---\n> >  archive.c |   17 +++++------------\n> >  1 file changed, 5 insertions(+), 12 deletions(-)\n> > \n> > diff --git a/archive.c b/archive.c\n> > index cd083ea..ecc1ff0 100644\n> > --- a/archive.c\n> > +++ b/archive.c\n> > @@ -254,18 +254,11 @@ static void parse_treeish_arg(const char **argv,\n> >  \t/* Remotes are only allowed to fetch actual refs */\n> >  \tif (remote) {\n> >  \t\tchar *ref = NULL;\n> > -\t\tconst char *refname, *colon = NULL;\n> > -\n> > -\t\tcolon = strchr(name, ':');\n> > -\t\tif (colon)\n> > -\t\t\trefname = xstrndup(name, colon - name);\n> > -\t\telse\n> > -\t\t\trefname = name;\n> > -\n> > -\t\tif (!dwim_ref(refname, strlen(refname), sha1, &ref))\n> > -\t\t\tdie(\"no such ref: %s\", refname);\n> > -\t\tif (refname != name)\n> > -\t\t\tfree((void *)refname);\n> > +\t\tconst char *colon = strchr(name, ':');\n> > +\t\tsize_t refnamelen = colon ? colon - name : strlen(name);\n> > +\n> > +\t\tif (!dwim_ref(name, refnamelen, sha1, &ref))\n> > +\t\t\tdie(\"no such ref: %.*s\", refnamelen, name);\n> >  \t\tfree(ref);\n> \n> Looks obviously correct to me.\n\nYep, that's clearly a much better way of doing it.\n\n   cmn\n"},{"id":"191671","messageId":"xmqq1umh4aeh.fsf@junio.mtv.corp.google.com","threadId":"30550","inReplyTo":"4FB5DAE5.6020307@lsrfire.ath.cx","subject":"Re: [PATCH] archive: simplify refname handling","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-05-18T18:22:14Z","receivedAt":"2012-05-18T18:22:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Looks good to me.  Thanks.\n"},{"id":"191672","messageId":"xmqqwr492vl7.fsf@junio.mtv.corp.google.com","threadId":"30550","inReplyTo":"4FB5DAE5.6020307@lsrfire.ath.cx","subject":"Re: [PATCH] archive: simplify refname handling","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-05-18T18:27:32Z","receivedAt":"2012-05-18T18:27:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:\n\n> +\t\tconst char *colon = strchr(name, ':');\n> +\t\tsize_t refnamelen = colon ? colon - name : strlen(name);\n> +\n> +\t\tif (!dwim_ref(name, refnamelen, sha1, &ref))\n> +\t\t\tdie(\"no such ref: %.*s\", refnamelen, name);\n>  \t\tfree(ref);\n>  \t}\n\nBoth dwim_ref()'s second parameter the vararg that corresponds to the\nlength part of \"%.*s\" in die(), expect \"int\", not \"size_t\", so I needed\nthis to get it compile.\n\n archive.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/archive.c b/archive.c\nindex 081ecb5..1e7156d 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -261,7 +261,7 @@ static void parse_treeish_arg(const char **argv,\n \tif (remote) {\n \t\tchar *ref = NULL;\n \t\tconst char *colon = strchr(name, ':');\n-\t\tsize_t refnamelen = colon ? colon - name : strlen(name);\n+\t\tint refnamelen = colon ? colon - name : strlen(name);\n \n \t\tif (!dwim_ref(name, refnamelen, sha1, &ref))\n \t\t\tdie(\"no such ref: %.*s\", refnamelen, name);\n"}]}