summaryrefslogtreecommitdiff
path: root/builtin-checkout.c
diff options
context:
space:
mode:
authorDaniel Barkalow <barkalow@iabervon.org>2008-02-19 07:52:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2008-02-19 08:25:52 (GMT)
commit569012bf91ddb25220483e8912e079ce8a501525 (patch)
tree2bf1cc33466fe62aa46cf5bd0bb4f6e13547f42a /builtin-checkout.c
parentb249b552e012824f1bd5026187bf9b895c2132c6 (diff)
downloadgit-569012bf91ddb25220483e8912e079ce8a501525.zip
git-569012bf91ddb25220483e8912e079ce8a501525.tar.gz
git-569012bf91ddb25220483e8912e079ce8a501525.tar.bz2
Clean up reporting differences on branch switch
This also changes it such that: $ git checkout will give the same information without changing branches. This is good for finding out if the fetch you did recently had anything to say about the branch you've been on, whose name you don't remember at the moment. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-checkout.c')
-rw-r--r--builtin-checkout.c78
1 files changed, 7 insertions, 71 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 0d19835..5291f72 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -291,71 +291,6 @@ static int merge_working_tree(struct checkout_opts *opts,
return 0;
}
-/*
- * We really should allow cb_data... Yuck
- */
-static const char *branch_name;
-static int branch_name_len;
-static char *found_remote;
-static char *found_merge;
-static int read_branch_config(const char *var, const char *value)
-{
- const char *name;
- if (prefixcmp(var, "branch."))
- return 0; /* not ours */
- name = var + strlen("branch.");
- if (strncmp(name, branch_name, branch_name_len) ||
- name[branch_name_len] != '.')
- return 0; /* not ours either */
- if (!strcmp(name + branch_name_len, ".remote")) {
- /*
- * Yeah, I know Christian's clean-up should
- * be used here, but the topic is based on an
- * older fork point.
- */
- if (!value)
- return error("'%s' not string", var);
- found_remote = xstrdup(value);
- return 0;
- }
- if (!strcmp(name + branch_name_len, ".merge")) {
- if (!value)
- return error("'%s' not string", var);
- found_merge = xstrdup(value);
- return 0;
- }
- return 0; /* not ours */
-}
-
-static int find_build_base(const char *ours, char **base)
-{
- struct remote *remote;
- struct refspec spec;
-
- *base = NULL;
-
- branch_name = ours + strlen("refs/heads/");
- branch_name_len = strlen(branch_name);
- found_remote = NULL;
- found_merge = NULL;
- git_config(read_branch_config);
-
- if (!found_remote || !found_merge) {
- cleanup:
- free(found_remote);
- free(found_merge);
- return 0;
- }
-
- remote = remote_get(found_remote);
- memset(&spec, 0, sizeof(spec));
- spec.src = found_merge;
- if (remote_find_tracking(remote, &spec))
- goto cleanup;
- *base = spec.dst;
- return 1;
-}
-
static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *opts)
{
/*
@@ -369,15 +304,16 @@ static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *op
const char *msgfmt;
char symmetric[84];
int show_log;
+ struct branch *branch = branch_get(NULL);
- if (!resolve_ref(new->path, sha1, 1, NULL))
+ if (!branch || !branch->merge)
return;
- ours = lookup_commit(sha1);
- if (!find_build_base(new->path, &base))
- return;
+ base = branch->merge[0]->dst;
+
+ ours = new->commit;
- sprintf(symmetric, "%s", sha1_to_hex(sha1));
+ sprintf(symmetric, "%s", sha1_to_hex(ours->object.sha1));
/*
* Ok, it is tracking base; is it ahead of us?
@@ -466,7 +402,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
}
remove_branch_state();
strbuf_release(&msg);
- if (new->path)
+ if (new->path || !strcmp(new->name, "HEAD"))
adjust_to_tracking(new, opts);
}