[PATCH 2/4] Extract function trim_url and optimize calls of it.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Extract compact code into trim_url. Dont call it every iteration in the loop since no reason.

Signed-off-by: Vasyl' Vavrychuk <vvavrychuk@xxxxxxxxx>
---
 builtin/fetch.c |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/builtin/fetch.c b/builtin/fetch.c
index 2b0b11e..46d8fd6 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -89,6 +89,19 @@ static void unlock_pack_on_signal(int signo)
 	raise(signo);
 }
 
+static void trim_url(char *url)
+{
+	int i, url_len;
+
+	url_len = strlen(url);
+	for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)
+		;
+	url_len = i + 1;
+	if (4 < i && !strncmp(".git", url + i - 3, 4))
+		url_len = i - 3;
+	url[url_len] = '\0';
+}
+
 static void add_merge_config(struct ref **head,
 			   const struct ref *remote_refs,
 		           struct branch *branch,
@@ -329,7 +342,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 {
 	FILE *fp;
 	struct commit *commit;
-	int url_len, i, note_len, shown_url = 0, rc = 0;
+	int i, note_len, shown_url = 0, rc = 0;
 	char note[1024];
 	const char *what, *kind;
 	struct ref *rm;
@@ -339,10 +352,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 	if (!fp)
 		return error("cannot open %s: %s\n", filename, strerror(errno));
 
-	if (raw_url)
+	if (raw_url) {
 		url = transport_anonymize_url(raw_url);
-	else
+		trim_url(url);
+	} else {
 		url = xstrdup("foreign");
+	}
 	for (rm = ref_map; rm; rm = rm->next) {
 		struct ref *ref = NULL;
 
@@ -379,14 +394,6 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 			what = rm->name;
 		}
 
-		url_len = strlen(url);
-		for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)
-			;
-		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) {
 			if (*kind)
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]