{"thread":{"id":"3026","subject":"[PATCH] show-branch: take default arguments from configuration file.","startedAt":"2006-01-10T02:53:13Z","lastAt":"2006-01-10T02:53:13Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"14386","messageId":"7vr77gbxpi.fsf@assigned-by-dhcp.cox.net","threadId":"3026","inReplyTo":null,"subject":"[PATCH] show-branch: take default arguments from configuration file.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-10T02:53:13Z","receivedAt":"2006-01-10T02:53:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This lets showbranch.default multivalued configuration item to\nbe used as the default set of parameters to git-show-branch when\nnone is given on the command line.\n\nI keep many topic branches (e.g. zzz/pack, net/misc) and\nbranches used only as a reference under subdirectories\n(e.g. hold/{html,man,todo} track the same from git.git, but\nclutters the show-branch output when shown along with the main\ndevelopment; ko/master tracks what I have pushed out already and\nrefetched from the kernel.org server), and often run:\n\n\t$ git show-branch ko/master heads/*\n\nto view only the ko/master head and branches I keep immediately\nunder $GIT_DIR/refs/heads.  With this change, I can have this in\nmy $GIT_DIR/config file:\n\n\t[showbranch]\n\t\tdefault = ko/master\n\t\tdefault = heads/*\n\nand say\n\n\t$ git show-branch\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n * This is \"master\" aka \"toward 1.2\" material, not meant for\n   1.1.1, but maybe we should allow trivial backports?  I\n   haven't decided.\n\n show-branch.c |   32 +++++++++++++++++++++++++++++++-\n 1 files changed, 31 insertions(+), 1 deletions(-)\n\n680c6ea5291057fcba95f00455260ab1c1b242eb\ndiff --git a/show-branch.c b/show-branch.c\nindex 15b1968..f43c406 100644\n--- a/show-branch.c\n+++ b/show-branch.c\n@@ -7,6 +7,10 @@\n static const char show_branch_usage[] =\n \"git-show-branch [--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+static char **default_arg = NULL;\n+\n #define UNINTERESTING\t01\n \n #define REV_SHIFT\t 2\n@@ -508,6 +512,21 @@ static void append_one_rev(const char *a\n \tdie(\"bad sha1 reference %s\", av);\n }\n \n+static int git_show_branch_config(const char *var, const char *value)\n+{\n+\tif (!strcmp(var, \"showbranch.default\")) {\n+\t\tif (default_alloc <= default_num + 1) {\n+\t\t\tdefault_alloc = default_alloc * 3 / 2 + 20;\n+\t\t\tdefault_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);\n+\t\t}\n+\t\tdefault_arg[default_num++] = strdup(value);\n+\t\tdefault_arg[default_num] = NULL;\n+\t\treturn 0;\n+\t}\n+\n+\treturn git_default_config(var, value);\n+}\n+\n int main(int ac, char **av)\n {\n \tstruct commit *rev[MAX_REVS], *commit;\n@@ -527,11 +546,22 @@ int main(int ac, char **av)\n \tint shown_merge_point = 0;\n \tint topo_order = 0;\n \n+\tgit_config(git_show_branch_config);\n \tsetup_git_directory();\n \n+\t/* If nothing is specified, try the default first */\n+\tif (ac == 1 && default_num) {\n+\t\tac = default_num + 1;\n+\t\tav = default_arg - 1; /* ick; we would not address av[0] */\n+\t}\n+\n \twhile (1 < ac && av[1][0] == '-') {\n \t\tchar *arg = av[1];\n-\t\tif (!strcmp(arg, \"--all\"))\n+\t\tif (!strcmp(arg, \"--\")) {\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-- \n1.1.0\n"}]}