{"thread":{"id":"6080","subject":"[PATCH] Make git-show-branch options similar to git-branch.","startedAt":"2006-12-22T13:58:39Z","lastAt":"2006-12-22T13:58:39Z","messageCount":1,"participants":["Brian Gernhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"30058","messageId":"20061222135839.GB26084@179.242.249.10.in-addr.arpa","threadId":"6080","inReplyTo":null,"subject":"[PATCH] Make git-show-branch options similar to git-branch.","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2006-12-22T13:58:39Z","receivedAt":"2006-12-22T13:58:39Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"Branch has \"-r\" for remote branches and \"-a\" for local and remote.\nSeems logical to mirror that in show-branch.  Also removes the\ndubiously useful \"--tags\" option (as part of changing the meaning for\n\"--all\").\n\nSigned-off-by: Brian Gernhardt <benji@silverinsanity.com>\n---\n\n Similar to my eariler patch but instead of wanting to add --remotes\n for completeness I now want to add it to mirror \"git branch\".  By the\n prinicple of least surprise, \"git branch -a\" and \"git show-branch -a\"\n should display the same refs.  (Same for \"-r\".)\n\n Documentation/git-show-branch.txt |   10 +++++---\n builtin-show-branch.c             |   40 ++++++++++++++++++++++++-------------\n 2 files changed, 32 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt\nindex 948ff10..dafacd4 100644\n--- a/Documentation/git-show-branch.txt\n+++ b/Documentation/git-show-branch.txt\n@@ -8,7 +8,7 @@ git-show-branch - Show branches and their commits\n SYNOPSIS\n --------\n [verse]\n-'git-show-branch' [--all] [--heads] [--tags] [--topo-order] [--current]\n+'git-show-branch' [--all] [--remotes] [--topo-order] [--current]\n \t\t[--more=<n> | --list | --independent | --merge-base]\n \t\t[--no-name | --sha1-name] [--topics] [<rev> | <glob>]...\n \n@@ -37,9 +37,11 @@ OPTIONS\n \tbranches under $GIT_DIR/refs/heads/topic, giving\n \t`topic/*` would show all of them.\n \n---all --heads --tags::\n-\tShow all refs under $GIT_DIR/refs, $GIT_DIR/refs/heads,\n-\tand $GIT_DIR/refs/tags, respectively.\n+-r|--remotes::\n+\tShow the remote-tracking branches.\n+\n+-a|--all::\n+\tShow both remote-tracking branches and local branches.\n \n --current::\n \tWith this option, the command includes the current\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex b9d9781..c67f2fa 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -4,7 +4,7 @@\n #include \"builtin.h\"\n \n static const char show_branch_usage[] =\n-\"git-show-branch [--sparse] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n] <branch>\";\n+\"git-show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n] <branch>\";\n \n static int default_num;\n static int default_alloc;\n@@ -383,6 +383,20 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f\n \treturn append_ref(refname + ofs, sha1, flag, cb_data);\n }\n \n+static int append_remote_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+{\n+\tunsigned char tmp[20];\n+\tint ofs = 13;\n+\tif (strncmp(refname, \"refs/remotes/\", ofs))\n+\t\treturn 0;\n+\t/* If both heads/foo and tags/foo exists, get_sha1 would\n+\t * get confused.\n+\t */\n+\tif (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))\n+\t\tofs = 5;\n+\treturn append_ref(refname + ofs, sha1, flag, cb_data);\n+}\n+\n static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n {\n \tif (strncmp(refname, \"refs/tags/\", 10))\n@@ -423,16 +437,16 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i\n \treturn append_ref(refname, sha1, flag, cb_data);\n }\n \n-static void snarf_refs(int head, int tag)\n+static void snarf_refs(int head, int remotes)\n {\n \tif (head) {\n \t\tint orig_cnt = ref_name_cnt;\n \t\tfor_each_ref(append_head_ref, NULL);\n \t\tsort_ref_range(orig_cnt, ref_name_cnt);\n \t}\n-\tif (tag) {\n+\tif (remotes) {\n \t\tint orig_cnt = ref_name_cnt;\n-\t\tfor_each_ref(append_tag_ref, NULL);\n+\t\tfor_each_ref(append_remote_ref, NULL);\n \t\tsort_ref_range(orig_cnt, ref_name_cnt);\n \t}\n }\n@@ -554,7 +568,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \tstruct commit_list *list = NULL, *seen = NULL;\n \tunsigned int rev_mask[MAX_REVS];\n \tint num_rev, i, extra = 0;\n-\tint all_heads = 0, all_tags = 0;\n+\tint all_heads = 0, all_remotes = 0;\n \tint all_mask, all_revs;\n \tint lifo = 1;\n \tchar head[128];\n@@ -586,12 +600,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\tac--; av++;\n \t\t\tbreak;\n \t\t}\n-\t\telse if (!strcmp(arg, \"--all\"))\n-\t\t\tall_heads = all_tags = 1;\n-\t\telse if (!strcmp(arg, \"--heads\"))\n-\t\t\tall_heads = 1;\n-\t\telse if (!strcmp(arg, \"--tags\"))\n-\t\t\tall_tags = 1;\n+\t\telse if (!strcmp(arg, \"--all\") || !strcmp(arg, \"-a\"))\n+\t\t\tall_heads = all_remotes = 1;\n+\t\telse if (!strcmp(arg, \"--remotes\") || !strcmp(arg, \"-r\"))\n+\t\t\tall_remotes = 1;\n \t\telse if (!strcmp(arg, \"--more\"))\n \t\t\textra = 1;\n \t\telse if (!strcmp(arg, \"--list\"))\n@@ -636,11 +648,11 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\tusage(show_branch_usage);\n \n \t/* If nothing is specified, show all branches by default */\n-\tif (ac + all_heads + all_tags == 0)\n+\tif (ac + all_heads + all_remotes == 0)\n \t\tall_heads = 1;\n \n-\tif (all_heads + all_tags)\n-\t\tsnarf_refs(all_heads, all_tags);\n+\tif (all_heads + all_remotes)\n+\t\tsnarf_refs(all_heads, all_remotes);\n \tif (reflog) {\n \t\tint reflen;\n \t\tif (!ac)\n-- \n1.4.4.GIT\n"}]}