{"thread":{"id":"12198","subject":"[PATCH] Clean up reporting differences on branch switch","startedAt":"2008-02-19T07:52:14Z","lastAt":"2008-02-19T07:52:14Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"69246","messageId":"alpine.LNX.1.00.0802190249540.5816@iabervon.org","threadId":"12198","inReplyTo":null,"subject":"[PATCH] Clean up reporting differences on branch switch","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-02-19T07:52:14Z","receivedAt":"2008-02-19T07:52:14Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This also changes it such that:\n\n$ git checkout\n\nwill give the same information without changing branches. This is good\nfor finding out if the fetch you did recently had anything to say\nabout the branch you've been on, whose name you don't remember at the\nmoment.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\nOn top of next, of course.\n\n builtin-checkout.c |   78 ++++-----------------------------------------------\n 1 files changed, 7 insertions(+), 71 deletions(-)\n\ndiff --git a/builtin-checkout.c b/builtin-checkout.c\nindex 9370ba0..cb75c9e 100644\n--- a/builtin-checkout.c\n+++ b/builtin-checkout.c\n@@ -291,71 +291,6 @@ static int merge_working_tree(struct checkout_opts *opts,\n \treturn 0;\n }\n \n-/*\n- * We really should allow cb_data... Yuck\n- */\n-static const char *branch_name;\n-static int branch_name_len;\n-static char *found_remote;\n-static char *found_merge;\n-static int read_branch_config(const char *var, const char *value)\n-{\n-\tconst char *name;\n-\tif (prefixcmp(var, \"branch.\"))\n-\t\treturn 0; /* not ours */\n-\tname = var + strlen(\"branch.\");\n-\tif (strncmp(name, branch_name, branch_name_len) ||\n-\t    name[branch_name_len] != '.')\n-\t\treturn 0; /* not ours either */\n-\tif (!strcmp(name + branch_name_len, \".remote\")) {\n-\t\t/*\n-\t\t * Yeah, I know Christian's clean-up should\n-\t\t * be used here, but the topic is based on an\n-\t\t * older fork point.\n-\t\t */\n-\t\tif (!value)\n-\t\t\treturn error(\"'%s' not string\", var);\n-\t\tfound_remote = xstrdup(value);\n-\t\treturn 0;\n-\t}\n-\tif (!strcmp(name + branch_name_len, \".merge\")) {\n-\t\tif (!value)\n-\t\t\treturn error(\"'%s' not string\", var);\n-\t\tfound_merge = xstrdup(value);\n-\t\treturn 0;\n-\t}\n-\treturn 0; /* not ours */\n-}\n-\n-static int find_build_base(const char *ours, char **base)\n-{\n-\tstruct remote *remote;\n-\tstruct refspec spec;\n-\n-\t*base = NULL;\n-\n-\tbranch_name = ours + strlen(\"refs/heads/\");\n-\tbranch_name_len = strlen(branch_name);\n-\tfound_remote = NULL;\n-\tfound_merge = NULL;\n-\tgit_config(read_branch_config);\n-\n-\tif (!found_remote || !found_merge) {\n-\tcleanup:\n-\t\tfree(found_remote);\n-\t\tfree(found_merge);\n-\t\treturn 0;\n-\t}\n-\n-\tremote = remote_get(found_remote);\n-\tmemset(&spec, 0, sizeof(spec));\n-\tspec.src = found_merge;\n-\tif (remote_find_tracking(remote, &spec))\n-\t\tgoto cleanup;\n-\t*base = spec.dst;\n-\treturn 1;\n-}\n-\n static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *opts)\n {\n \t/*\n@@ -369,15 +304,16 @@ static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *op\n \tconst char *msgfmt;\n \tchar symmetric[84];\n \tint show_log;\n+\tstruct branch *branch = branch_get(NULL);\n \n-\tif (!resolve_ref(new->path, sha1, 1, NULL))\n+\tif (!branch || !branch->merge)\n \t\treturn;\n-\tours = lookup_commit(sha1);\n \n-\tif (!find_build_base(new->path, &base))\n-\t\treturn;\n+\tbase = branch->merge[0]->dst;\n+\n+\tours = new->commit;\n \n-\tsprintf(symmetric, \"%s\", sha1_to_hex(sha1));\n+\tsprintf(symmetric, \"%s\", sha1_to_hex(ours->object.sha1));\n \n \t/*\n \t * Ok, it is tracking base; is it ahead of us?\n@@ -466,7 +402,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,\n \t}\n \tremove_branch_state();\n \tstrbuf_release(&msg);\n-\tif (new->path)\n+\tif (new->path || !strcmp(new->name, \"HEAD\"))\n \t\tadjust_to_tracking(new, opts);\n }\n \n-- \n1.5.4.1.1350.g2b9ee\n"}]}