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

Re: [PATCH 1/4] Reduce url_len variable scope

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 17, 2011, 01:43 UTC
Message-ID
<7vhbc3fnad.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1297550311-17723-2-git-send-email-vvavrychuk@gmail.com>
Vasyl' Vavrychuk <vvavrychuk@gmail.com> writes:
> Subject: Re: [PATCH 1/4] Reduce url_len variable scope

Please mark the patch in such a way that the readers can tell what file/function this patch is about by reading "git shortlog" output without anything else, i.e.

	Subject: builtin/fetch.c: shorten lifetime of the url_len variable

Hmph. While this does not bring in any new bug to the code, what benefit do we gain from it?

The scope is not reduced (even though the variable's lifespan is shortened in the scope). Are we so short of registers that this change matters?

Show 36 quoted lines
>  builtin/fetch.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 357f3cd..2b0b11e 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -385,6 +385,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
>  		url_len = i + 1;
>  		if (4 < i && !strncmp(".git", url + i - 3, 4))
>  			url_len = i - 3;
> +		url[url_len] = '\0';
>  
>  		note_len = 0;
>  		if (*what) {
> @@ -399,7 +400,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
>  				    rm->old_sha1),
>  			rm->merge ? "" : "not-for-merge",
>  			note);
> -		for (i = 0; i < url_len; ++i)
> +		for (i = 0; url[i]; ++i)
>  			if ('\n' == url[i])
>  				fputs("\\n", fp);
>  			else
> @@ -415,8 +416,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
>  				 REFCOL_WIDTH, *what ? what : "HEAD");
>  		if (*note) {
>  			if (verbosity >= 0 && !shown_url) {
> -				fprintf(stderr, "From %.*s\n",
> -						url_len, url);
> +				fprintf(stderr, "From %s\n", url);
>  				shown_url = 1;
>  			}
>  			if (verbosity >= 0)
> -- 
> 1.7.1
Previous: Vasyl' VavrychukNext: Vasyl' Vavrychuk
Message 3 of 12 in “clean-up store_updated_refs”
  1. 0/4 clean-up store_updated_refsVasyl' Vavrychuk, Feb 12, 2011
  2. 1/4 Reduce url_len variable scopeVasyl' Vavrychuk, Feb 12, 2011
  3. Junio C HamanoFeb 17, 2011
  4. 2/4 Extract function trim_url and optimize calls of it.Vasyl' Vavrychuk, Feb 12, 2011
  5. Junio C HamanoFeb 17, 2011
  6. 3/4 Dont use the same variable for different thingsVasyl' Vavrychuk, Feb 12, 2011
  7. Junio C HamanoFeb 17, 2011
  8. João P. SampaioFeb 17, 2011
  9. 4/4 Replace pointer arithmetic with strbufVasyl' Vavrychuk, Feb 12, 2011
  10. Sverre RabbelierFeb 13, 2011
  11. Vasyl'Feb 13, 2011
  12. Sverre RabbelierFeb 13, 2011

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.