Thread (12 messages) flat view 12 messages, 4 authors, 2016-06-15

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:35

Vasyl' Vavrychuk [off-list ref] 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?
quoted hunk ↗ jump to hunk
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help