[PATCH RFC 3/8] git remote add: refactor configuration

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

 



This moves the configuration setup of git remote add to
a separate function.  The next patch will add more
configuration options in setup_remote_config.

Signed-off-by: Paolo Bonzini <bonzini@xxxxxxx>
---
 builtin-remote.c |   74 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/builtin-remote.c b/builtin-remote.c
index 008abfe..c30fbb7 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -36,6 +36,49 @@ static inline int postfixcmp(const char *string, const char *postfix)
 	return strcmp(string + len1 - len2, postfix);
 }
 
+static int setup_remote_config(const char *name, const char *url, int mirror, struct string_list *track)
+{
+	struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
+	int i;
+
+	if (mirror) {
+		strbuf_reset(&buf);
+		strbuf_addf(&buf, "remote.%s.mirror", name);
+		if (git_config_set(buf.buf, "true"))
+			return 1;
+	}
+
+	strbuf_reset(&buf);
+	strbuf_addf(&buf, "remote.%s.url", name);
+	if (git_config_set(buf.buf, url))
+		return 1;
+
+	strbuf_reset(&buf);
+	strbuf_addf(&buf, "remote.%s.fetch", name);
+
+	if (track->nr == 0)
+		string_list_append("*", track);
+
+	for (i = 0; i < track->nr; i++) {
+		struct string_list_item *item = track->items + i;
+
+		strbuf_reset(&buf2);
+		if (mirror)
+			strbuf_addf(&buf2, "+refs/%s:refs/%s",
+					item->string, item->string);
+		else
+			strbuf_addf(&buf2, "+refs/heads/%s:refs/remotes/%s/%s",
+					item->string, name, item->string);
+		if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
+			return 1;
+	}
+
+	strbuf_release(&buf);
+	strbuf_release(&buf2);
+	return 0;
+}
+
+
 static int opt_parse_track(const struct option *opt, const char *arg, int not)
 {
 	struct string_list *list = opt->value;
@@ -67,7 +110,6 @@ static int add(int argc, const char **argv)
 	struct remote *remote;
 	struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
 	const char *name, *url;
-	int i;
 
 	struct option options[] = {
 		OPT_GROUP("add specific options"),
@@ -97,37 +139,9 @@ static int add(int argc, const char **argv)
 	if (!valid_fetch_refspec(buf2.buf))
 		die("'%s' is not a valid remote name", name);
 
-	strbuf_addf(&buf, "remote.%s.url", name);
-	if (git_config_set(buf.buf, url))
+	if (setup_remote_config(name, url, mirror, &track))
 		return 1;
 
-	strbuf_reset(&buf);
-	strbuf_addf(&buf, "remote.%s.fetch", name);
-
-	if (track.nr == 0)
-		string_list_append("*", &track);
-	for (i = 0; i < track.nr; i++) {
-		struct string_list_item *item = track.items + i;
-
-		strbuf_reset(&buf2);
-		strbuf_addch(&buf2, '+');
-		if (mirror)
-			strbuf_addf(&buf2, "refs/%s:refs/%s",
-					item->string, item->string);
-		else
-			strbuf_addf(&buf2, "refs/heads/%s:refs/remotes/%s/%s",
-					item->string, name, item->string);
-		if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
-			return 1;
-	}
-
-	if (mirror) {
-		strbuf_reset(&buf);
-		strbuf_addf(&buf, "remote.%s.mirror", name);
-		if (git_config_set(buf.buf, "true"))
-			return 1;
-	}
-
 	if (fetch && fetch_remote(name))
 		return 1;
 
-- 
1.6.2.5

--
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]