git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <bonzini@gnu.org>
To: <git@vger.kernel.org>
Subject: [PATCH RFC 3/8] git remote add: refactor configuration
Date: Mon, 20 Jul 2009 19:49:50 +0200	[thread overview]
Message-ID: <1248112195-3761-4-git-send-email-bonzini@gnu.org> (raw)
In-Reply-To: <1248112195-3761-1-git-send-email-bonzini@gnu.org>

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@gnu.org>
---
 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

  parent reply	other threads:[~2009-07-20 17:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-20 17:49 [PATCH RFC 0/8] introduce 'git remote add --push' and 'git clone --push' Paolo Bonzini
2009-07-20 17:49 ` [PATCH RFC 1/8] reintroduce PUSH_DEFAULT_UNSPECIFIED Paolo Bonzini
2009-07-20 17:49 ` [PATCH RFC 2/8] push: add push.default = mirror Paolo Bonzini
2009-07-20 20:46   ` Junio C Hamano
2009-07-20 21:14     ` Paolo Bonzini
2009-07-20 21:34       ` Junio C Hamano
2009-07-20 21:36         ` Paolo Bonzini
2009-07-20 17:49 ` Paolo Bonzini [this message]
2009-07-20 17:49 ` [PATCH RFC 4/8] git remote add: add --push option Paolo Bonzini
2009-07-20 17:49 ` [PATCH RFC 5/8] clone: refactoring of building the fetch refspec Paolo Bonzini
2009-07-20 17:49 ` [PATCH RFC 6/8] clone: use setup_remote_config Paolo Bonzini
2009-07-20 17:49 ` [PATCH RFC 7/8] config: add git_config_norepo Paolo Bonzini
2009-07-20 17:49 ` [PATCH RFC 8/8] clone: add --push option Paolo Bonzini
2009-07-20 22:15 ` [PATCH RFC 0/8] introduce 'git remote add --push' and 'git clone --push' Junio C Hamano
2009-07-21 10:33   ` Paolo Bonzini
2009-07-21 21:00     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1248112195-3761-4-git-send-email-bonzini@gnu.org \
    --to=bonzini@gnu.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).