{"thread":{"id":"3055","subject":"[PATCH] show-branch: always include the current branch.","startedAt":"2006-01-12T00:05:50Z","lastAt":"2006-01-12T00:05:50Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"14522","messageId":"7vace2joo1.fsf@assigned-by-dhcp.cox.net","threadId":"3055","inReplyTo":null,"subject":"[PATCH] show-branch: always include the current branch.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-12T00:05:50Z","receivedAt":"2006-01-12T00:05:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"By default, the command includes the current branch to the list\nof revs to be shown, even when it is not given on the command\nline.  A new flag, --no-current, disables it.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n * Currently in \"pu\".\n\n Documentation/git-show-branch.txt |   13 ++++++++--\n show-branch.c                     |   49 ++++++++++++++++++++++++++-----------\n 2 files changed, 46 insertions(+), 16 deletions(-)\n\n95a7c01ab91b71f72b6d5d60da7659b2b625fa6d\ndiff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt\nindex 9cc44a8..90e2a5c 100644\n--- a/Documentation/git-show-branch.txt\n+++ b/Documentation/git-show-branch.txt\n@@ -7,7 +7,10 @@ git-show-branch - Show branches and thei\n \n SYNOPSIS\n --------\n-'git-show-branch [--all] [--heads] [--tags] [--topo-order] [--more=<n> | --list | --independent | --merge-base] [--no-name | --sha1-name] [<rev> | <glob>]...'\n+[verse]\n+git-show-branch [--all] [--heads] [--tags] [--topo-order] [--no-current]\n+\t[--more=<n> | --list | --independent | --merge-base]\n+\t[--no-name | --sha1-name] [<rev> | <glob>]...\n \n DESCRIPTION\n -----------\n@@ -38,6 +41,11 @@ OPTIONS\n \tShow all refs under $GIT_DIR/refs, $GIT_DIR/refs/heads,\n \tand $GIT_DIR/refs/tags, respectively.\n \n+--no-current::\n+\tBy default, the command includes the current branch to\n+\tthe list of revs to be shown even when it is not given\n+\ton the command line.  This flag disables it.\n+\n --topo-order::\n         By default, the branches and their commits are shown in\n         reverse chronological order.  This option makes them\n@@ -133,7 +141,8 @@ it, having the following in the configur\n ------------\n \n With this,`git show-branch` without extra parameters would show\n-only the primary branches.\n+only the primary branches.  In addition, if you happen to be on\n+your topic branch, it is shown as well.\n \n \n \ndiff --git a/show-branch.c b/show-branch.c\nindex f43c406..9f7e188 100644\n--- a/show-branch.c\n+++ b/show-branch.c\n@@ -5,7 +5,7 @@\n #include \"refs.h\"\n \n static const char show_branch_usage[] =\n-\"git-show-branch [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [<refs>...]\";\n+\"git-show-branch [--no-current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [<refs>...]\";\n \n static int default_num = 0;\n static int default_alloc = 0;\n@@ -435,12 +435,12 @@ static void snarf_refs(int head, int tag\n \t}\n }\n \n-static int rev_is_head(char *head_path, int headlen,\n-\t\t       char *name,\n+static int rev_is_head(char *head_path, int headlen, char *name,\n \t\t       unsigned char *head_sha1, unsigned char *sha1)\n {\n \tint namelen;\n-\tif ((!head_path[0]) || memcmp(head_sha1, sha1, 20))\n+\tif ((!head_path[0]) ||\n+\t    (head_sha1 && sha1 && memcmp(head_sha1, sha1, 20)))\n \t\treturn 0;\n \tnamelen = strlen(name);\n \tif ((headlen < namelen) ||\n@@ -545,6 +545,7 @@ int main(int ac, char **av)\n \tint sha1_name = 0;\n \tint shown_merge_point = 0;\n \tint topo_order = 0;\n+\tint no_current_branch = 0;\n \n \tgit_config(git_show_branch_config);\n \tsetup_git_directory();\n@@ -573,6 +574,8 @@ int main(int ac, char **av)\n \t\t\textra = -1;\n \t\telse if (!strcmp(arg, \"--no-name\"))\n \t\t\tno_name = 1;\n+\t\telse if (!strcmp(arg, \"--no-current\"))\n+\t\t\tno_current_branch = 1;\n \t\telse if (!strcmp(arg, \"--sha1-name\"))\n \t\t\tsha1_name = 1;\n \t\telse if (!strncmp(arg, \"--more=\", 7))\n@@ -604,6 +607,34 @@ int main(int ac, char **av)\n \t\tac--; av++;\n \t}\n \n+\thead_path_p = resolve_ref(git_path(\"HEAD\"), head_sha1, 1);\n+\tif (head_path_p) {\n+\t\thead_path_len = strlen(head_path_p);\n+\t\tmemcpy(head_path, head_path_p, head_path_len + 1);\n+\t}\n+\telse {\n+\t\thead_path_len = 0;\n+\t\thead_path[0] = 0;\n+\t}\n+\n+\tif (!merge_base && !no_current_branch && head_path_p) {\n+\t\tint has_head = 0;\n+\t\tfor (i = 0; !has_head && i < ref_name_cnt; i++) {\n+\t\t\t/* We are only interested in adding the branch\n+\t\t\t * HEAD points at.\n+\t\t\t */\n+\t\t\tif (rev_is_head(head_path,\n+\t\t\t\t\thead_path_len,\n+\t\t\t\t\tref_name[i],\n+\t\t\t\t\thead_sha1, NULL))\n+\t\t\t\thas_head++;\n+\t\t}\n+\t\tif (!has_head) {\n+\t\t\tint pfxlen = strlen(git_path(\"refs/heads/\"));\n+\t\t\tappend_one_rev(head_path + pfxlen);\n+\t\t}\n+\t}\n+\n \tif (!ref_name_cnt) {\n \t\tfprintf(stderr, \"No revs to be shown.\\n\");\n \t\texit(0);\n@@ -639,16 +670,6 @@ int main(int ac, char **av)\n \tif (0 <= extra)\n \t\tjoin_revs(&list, &seen, num_rev, extra);\n \n-\thead_path_p = resolve_ref(git_path(\"HEAD\"), head_sha1, 1);\n-\tif (head_path_p) {\n-\t\thead_path_len = strlen(head_path_p);\n-\t\tmemcpy(head_path, head_path_p, head_path_len + 1);\n-\t}\n-\telse {\n-\t\thead_path_len = 0;\n-\t\thead_path[0] = 0;\n-\t}\n-\n \tif (merge_base)\n \t\treturn show_merge_base(seen, num_rev);\n \n-- \n1.1.1-g8ecb\n"}]}