From: Paolo Bonzini <bonzini@gnu.org>
To: <git@vger.kernel.org>
Subject: [PATCH RFC 6/8] clone: use setup_remote_config
Date: Mon, 20 Jul 2009 19:49:53 +0200 [thread overview]
Message-ID: <1248112195-3761-7-git-send-email-bonzini@gnu.org> (raw)
In-Reply-To: <1248112195-3761-1-git-send-email-bonzini@gnu.org>
We can now use setup_remote_config in builtin-clone.c and remove
duplicated computation of remote.*.fetch contents.
The three cases to consider are:
1) !option_bare. This is the easy case when setup_remote_config just
works and a normal refs/heads/*:refs/remotes/origin/* refspec is created.
This only requires a small new feature in setup_remote_config to pass
the refspec back to builtin-clone.c; setup_remote_config will simply store
it in the util field of the stringlist items.
2) option_bare && option_mirror. Again, setup_remote_config is used.
Passing PUSH_DEFAULT_MIRROR to option_mirror will use +refs/*:refs/*
for the refspec. There is a change from before, in that a remote.*.push
refspec will be setup as well.
3) option_bare && !option_mirror. In this case, no fetch refspec will
be configured (just as before), and setup_remote_config is not used.
Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
---
builtin-clone.c | 46 ++++++++++++++--------------------------------
builtin-remote.c | 5 +++--
remote.h | 3 +++
3 files changed, 20 insertions(+), 34 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index 345101a..68d8a68 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -19,6 +19,7 @@
#include "strbuf.h"
#include "dir.h"
#include "pack-refs.h"
+#include "string-list.h"
#include "sigchain.h"
#include "branch.h"
#include "remote.h"
@@ -348,7 +349,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
char *path, *dir;
int dest_exists;
const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
- struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
struct strbuf reflog_msg = STRBUF_INIT;
struct transport *transport = NULL;
int err = 0;
@@ -449,40 +449,24 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
- if (option_bare) {
- if (option_mirror)
- fetch_pattern = "+refs/*:refs/*";
- else
- fetch_pattern = "+refs/heads/*:refs/heads/*";
-
+ if (option_bare)
git_config_set("core.bare", "true");
- } else {
- strbuf_addf(&value, "+refs/heads/*:refs/remotes/%s/*:*",
- option_origin);
- fetch_pattern = value.buf;
- }
if (option_mirror || !option_bare) {
- /* Configure the remote */
- strbuf_addf(&key, "remote.%s.fetch", option_origin);
- git_config_set_multivar(key.buf, fetch_pattern, "^$", 0);
- strbuf_reset(&key);
-
- if (option_mirror) {
- strbuf_addf(&key, "remote.%s.mirror", option_origin);
- git_config_set(key.buf, "true");
- strbuf_reset(&key);
- }
-
- strbuf_addf(&key, "remote.%s.url", option_origin);
- git_config_set(key.buf, repo);
- strbuf_reset(&key);
+ struct string_list track = { NULL, 0, 0 };
+ setup_remote_config (option_origin, repo,
+ option_mirror
+ ? PUSH_DEFAULT_MIRROR
+ : PUSH_DEFAULT_NOTHING,
+ &track);
+ fetch_pattern = track.items[0].util;
+ refspec = parse_fetch_refspec(1, &fetch_pattern);
+ string_list_clear(&track, 1);
+ } else {
+ fetch_pattern = "+refs/heads/*:refs/heads/*";
+ refspec = parse_fetch_refspec(1, &fetch_pattern);
}
- refspec = parse_fetch_refspec(1, &fetch_pattern);
-
- strbuf_reset(&value);
-
if (path && !is_bundle)
refs = clone_local(path, git_dir);
else {
@@ -611,8 +595,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
}
strbuf_release(&reflog_msg);
- strbuf_release(&key);
- strbuf_release(&value);
junk_pid = 0;
return err;
}
diff --git a/builtin-remote.c b/builtin-remote.c
index 23ab24b..99c06bc 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -59,7 +59,7 @@ static void warn_unconfigured_push()
}
-static int setup_default_remote_config(const char *name, const char *url, int push, struct string_list *track)
+int setup_remote_config(const char *name, const char *url, int push, struct string_list *track)
{
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT;
const char *refspec = NULL;
@@ -154,6 +154,7 @@ static int setup_default_remote_config(const char *name, const char *url, int pu
else
strbuf_addf(&buf2, "+refs/heads/%s:refs/remotes/%s/%s",
item->string, name, item->string);
+ item->util = xstrdup (buf2.buf);
if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
return 1;
}
@@ -265,7 +266,7 @@ static int add(int argc, const char **argv)
strbuf_release(&buf);
strbuf_release(&buf2);
- string_list_clear(&track, 0);
+ string_list_clear(&track, 1);
return 0;
}
diff --git a/remote.h b/remote.h
index 86b18dc..64f4d58 100644
--- a/remote.h
+++ b/remote.h
@@ -115,6 +115,9 @@ struct ref *get_remote_ref(const struct ref *remote_refs, const char *name);
*/
int remote_find_tracking(struct remote *remote, struct refspec *refspec);
+struct string_list;
+int setup_remote_config(const char *name, const char *url, int push, struct string_list *track);
+
struct branch {
const char *name;
const char *refname;
--
1.6.2.5
next prev parent reply other threads:[~2009-07-20 17:51 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 ` [PATCH RFC 3/8] git remote add: refactor configuration Paolo Bonzini
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 ` Paolo Bonzini [this message]
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-7-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).