From: Paolo Bonzini <bonzini@gnu.org>
To: <git@vger.kernel.org>
Subject: [PATCH 2/6] branch: install_branch_config and struct tracking refactoring
Date: Sun, 12 Jul 2009 14:17:29 +0200 [thread overview]
Message-ID: <1247401053-20429-3-git-send-email-bonzini@gnu.org> (raw)
In-Reply-To: <1247401053-20429-1-git-send-email-bonzini@gnu.org>
This patch combines two small refactoring. The first is to store
a struct remote into struct tracking. The second is to pass a
struct remote instead of just the name to install_branch_config.
Together, these will allow to easily implement the new configuration
keys remote.*.autosetupmerge and remote.*.autosetuprebase.
Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
---
branch.c | 34 ++++++++++++++++++----------------
branch.h | 3 ++-
builtin-clone.c | 4 ++--
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/branch.c b/branch.c
index 05ef3f5..d17c5ec 100644
--- a/branch.c
+++ b/branch.c
@@ -7,7 +7,7 @@
struct tracking {
struct refspec spec;
char *src;
- const char *remote;
+ struct remote *remote;
int matches;
};
@@ -18,7 +18,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
if (!remote_find_tracking(remote, &tracking->spec)) {
if (++tracking->matches == 1) {
tracking->src = tracking->spec.src;
- tracking->remote = remote->name;
+ tracking->remote = remote;
} else {
free(tracking->spec.src);
if (tracking->src) {
@@ -32,7 +32,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
return 0;
}
-static int should_setup_rebase(const char *origin)
+static int should_setup_rebase(struct remote *origin)
{
switch (autorebase) {
case AUTOREBASE_NEVER:
@@ -47,17 +47,18 @@ static int should_setup_rebase(const char *origin)
return 0;
}
-void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
+void install_branch_config(int flag, const char *local, struct remote *remote,
+ const char *merge)
{
struct strbuf key = STRBUF_INIT;
- int rebasing = should_setup_rebase(origin);
+ int rebasing = should_setup_rebase(remote);
strbuf_addf(&key, "branch.%s.remote", local);
- git_config_set(key.buf, origin ? origin : ".");
+ git_config_set(key.buf, remote ? remote->name : ".");
strbuf_reset(&key);
strbuf_addf(&key, "branch.%s.merge", local);
- git_config_set(key.buf, remote);
+ git_config_set(key.buf, merge);
if (rebasing) {
strbuf_reset(&key);
@@ -68,16 +69,15 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
if (flag & BRANCH_CONFIG_VERBOSE) {
strbuf_reset(&key);
- strbuf_addstr(&key, origin ? "remote" : "local");
+ strbuf_addstr(&key, remote ? "remote" : "local");
/* Are we tracking a proper "branch"? */
- if (!prefixcmp(remote, "refs/heads/")) {
- strbuf_addf(&key, " branch %s", remote + 11);
- if (origin)
- strbuf_addf(&key, " from %s", origin);
- }
+ if (!prefixcmp(merge, "refs/heads/"))
+ strbuf_addf(&key, " branch %s", merge + 11);
else
- strbuf_addf(&key, " ref %s", remote);
+ strbuf_addf(&key, " ref %s", merge);
+ if (remote)
+ strbuf_addf(&key, " from %s", remote->name);
printf("Branch %s set up to track %s%s.\n",
local, key.buf,
rebasing ? " by rebasing" : "");
@@ -117,9 +117,11 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
return error("Not tracking: ambiguous information for ref %s",
orig_ref);
- install_branch_config(BRANCH_CONFIG_VERBOSE, new_ref, tracking.remote,
- tracking.src ? tracking.src : orig_ref);
+ if (!tracking.src)
+ tracking.src = xstrdup (orig_ref);
+ install_branch_config(BRANCH_CONFIG_VERBOSE, new_ref, tracking.remote,
+ tracking.src);
free(tracking.src);
return 0;
}
diff --git a/branch.h b/branch.h
index eed817a..f7c02c9 100644
--- a/branch.h
+++ b/branch.h
@@ -26,6 +26,7 @@ void remove_branch_state(void);
* taken from origin "origin".
*/
#define BRANCH_CONFIG_VERBOSE 01
-extern void install_branch_config(int flag, const char *local, const char *origin, const char *remote);
+struct remote;
+extern void install_branch_config(int flag, const char *local, struct remote *remote, const char *merge);
#endif
diff --git a/builtin-clone.c b/builtin-clone.c
index 32dea74..552ddf6 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -527,7 +527,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
remote_head = NULL;
option_no_checkout = 1;
if (!option_bare)
- install_branch_config(0, "master", option_origin,
+ install_branch_config(0, "master", remote_get(option_origin),
"refs/heads/master");
}
@@ -557,7 +557,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
head_points_at->peer_ref->name,
reflog_msg.buf);
- install_branch_config(0, head, option_origin,
+ install_branch_config(0, head, remote_get(option_origin),
head_points_at->name);
}
} else if (remote_head) {
--
1.6.2.5
next prev parent reply other threads:[~2009-07-12 12:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-12 12:17 [PATCH 0/6] Tracking setup improvements: per-remote config, autosetuppush Paolo Bonzini
2009-07-12 12:17 ` [PATCH 1/6] config: allow false and true values for branch.autosetuprebase Paolo Bonzini
2009-07-12 12:17 ` Paolo Bonzini [this message]
2009-07-12 12:17 ` [PATCH 3/6] introduce a struct tracking_config Paolo Bonzini
2009-07-12 12:17 ` [PATCH 4/6] remote: add per-remote autosetupmerge and autosetuprebase configuration Paolo Bonzini
2009-07-12 12:17 ` [PATCH 5/6] move deletion of merge configuration to branch.c Paolo Bonzini
2009-07-12 12:17 ` [PATCH 6/6] branch, checkout: introduce autosetuppush Paolo Bonzini
2009-07-12 21:17 ` [PATCH 0/6] Tracking setup improvements: per-remote config, autosetuppush 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=1247401053-20429-3-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).