{"thread":{"id":"27198","subject":"[RFC/PATCH 0/2] RFC/POC: patterns for branch list","startedAt":"2011-04-27T12:15:17Z","lastAt":"2011-04-27T17:10:00Z","messageCount":4,"participants":["Michael J Gruber","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"166509","messageId":"cover.1303906496.git.git@drmicha.warpmail.net","threadId":"27198","inReplyTo":null,"subject":"[RFC/PATCH 0/2] RFC/POC: patterns for branch list","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-04-27T12:15:17Z","receivedAt":"2011-04-27T12:15:17Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"This mini series is about introducing patterns to the list mode of\n'git branch' much like the pattern for 'git tag -l'. There are several\nthings which I would like to do but would like to rfc first:\n\n'-l' is the natural short option name for '--list'. This is taken for the\nrarely used or needed 'create reflog' option. I'd change the latter to\n'-g,--create-reflog' (cmp. log) and take '-l,--list' but know the reaction\nalready.\n\n'-v' and '-vv' both take considerable time (because they need to walk).\nIt makes more sense to have '-v' display cheap output (upstream name)\nand '-vv' add expensive output (ahead/behind info). '-vvv' could add super\nexpensive info (ahead/equivalent/behind a la cherry-mark).\n\nBut all of the above are changes to current (ui) behaviour. In the two patches\nbelow, only the automatic activation of the list mode with -v/-vv is a\nchange of (undocumented) behaviour.\n\nAnd yes, git-for-each-ref can do all this and more, but that is plumbing.\n\nMichael J Gruber (2):\n  branch: allow pattern arguments\n  branch: introduce --list argument\n\n builtin/branch.c |   21 +++++++++++++++------\n 1 files changed, 15 insertions(+), 6 deletions(-)\n\n-- \n1.7.5.270.gafca7\n"},{"id":"166511","messageId":"2d9a4893bd2ac8a402526c9876fa1a15f7cd8191.1303906496.git.git@drmicha.warpmail.net","threadId":"27198","inReplyTo":"cover.1303906496.git.git@drmicha.warpmail.net","subject":"[RFC/PATCH 1/2] branch: allow pattern arguments","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-04-27T12:15:18Z","receivedAt":"2011-04-27T12:15:18Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Allow pattern arguments for the list mode just like for git tag -l.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n builtin/branch.c |   13 +++++++++----\n 1 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 9cca1b9..10292ab 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -260,6 +260,7 @@ static char *resolve_symref(const char *src, const char *prefix)\n \n struct append_ref_cb {\n \tstruct ref_list *ref_list;\n+\tconst char *pattern;\n \tint ret;\n };\n \n@@ -297,6 +298,9 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,\n \tif ((kind & ref_list->kinds) == 0)\n \t\treturn 0;\n \n+\tif (cb->pattern && fnmatch(cb->pattern, refname, 0))\n+\t\treturn 0;\n+\n \tcommit = NULL;\n \tif (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {\n \t\tcommit = lookup_commit_reference_gently(sha1, 1);\n@@ -494,7 +498,7 @@ static void show_detached(struct ref_list *ref_list)\n \t}\n }\n \n-static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)\n+static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char *pattern)\n {\n \tint i;\n \tstruct append_ref_cb cb;\n@@ -508,6 +512,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru\n \tif (merge_filter != NO_FILTER)\n \t\tinit_revisions(&ref_list.revs, NULL);\n \tcb.ref_list = &ref_list;\n+\tcb.pattern = pattern;\n \tcb.ret = 0;\n \tfor_each_rawref(append_ref, &cb);\n \tif (merge_filter != NO_FILTER) {\n@@ -525,7 +530,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru\n \tqsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);\n \n \tdetached = (detached && (kinds & REF_LOCAL_BRANCH));\n-\tif (detached)\n+\tif (detached && (!pattern || !fnmatch(pattern, \"HEAD\", 0)))\n \t\tshow_detached(&ref_list);\n \n \tfor (i = 0; i < ref_list.index; i++) {\n@@ -700,8 +705,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \n \tif (delete)\n \t\treturn delete_branches(argc, argv, delete > 1, kinds);\n-\telse if (argc == 0)\n-\t\treturn print_ref_list(kinds, detached, verbose, abbrev, with_commit);\n+\telse if (argc == 0 || (verbose && argc == 1))\n+\t\treturn print_ref_list(kinds, detached, verbose, abbrev, with_commit, argc ? argv[0] : NULL);\n \telse if (rename && (argc == 1))\n \t\trename_branch(head, argv[0], rename > 1);\n \telse if (rename && (argc == 2))\n-- \n1.7.5.270.gafca7\n"},{"id":"166510","messageId":"90570cc5b04bf1f73833f365dc58a3d5ae200a21.1303906496.git.git@drmicha.warpmail.net","threadId":"27198","inReplyTo":"cover.1303906496.git.git@drmicha.warpmail.net","subject":"[RFC/PATCH 2/2] branch: introduce --list argument","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-04-27T12:15:19Z","receivedAt":"2011-04-27T12:15:19Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Currently, there is no way to invoke the list mode with a pattern\nbecause this is interpreted as branch creation.\n\nIntroduce a --list argument which invokes the list mode.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n builtin/branch.c |   10 +++++++---\n 1 files changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 10292ab..4ccd89c 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -619,7 +619,7 @@ static int opt_parse_merge_filter(const struct option *opt, const char *arg, int\n \n int cmd_branch(int argc, const char **argv, const char *prefix)\n {\n-\tint delete = 0, rename = 0, force_create = 0;\n+\tint delete = 0, rename = 0, force_create = 0, list = 0;\n \tint verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;\n \tint reflog = 0;\n \tenum branch_track track;\n@@ -658,6 +658,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT_BIT('D', NULL, &delete, \"delete branch (even if not merged)\", 2),\n \t\tOPT_BIT('m', NULL, &rename, \"move/rename a branch and its reflog\", 1),\n \t\tOPT_BIT('M', NULL, &rename, \"move/rename a branch, even if target exists\", 2),\n+\t\tOPT_BOOLEAN(0, \"list\", &list, \"list branch names\"),\n \t\tOPT_BOOLEAN('l', NULL, &reflog, \"create the branch's reflog\"),\n \t\tOPT__FORCE(&force_create, \"force creation (when already exists)\"),\n \t\t{\n@@ -700,12 +701,15 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \n \targc = parse_options(argc, argv, prefix, options, builtin_branch_usage,\n \t\t\t     0);\n-\tif (!!delete + !!rename + !!force_create > 1)\n+\tif (!!delete + !!rename + !!force_create + !!list > 1)\n \t\tusage_with_options(builtin_branch_usage, options);\n \n+\tif (argc == 0 || (verbose && argc == 1))\n+\t\tlist = 1;\n+\n \tif (delete)\n \t\treturn delete_branches(argc, argv, delete > 1, kinds);\n-\telse if (argc == 0 || (verbose && argc == 1))\n+\telse if (list)\n \t\treturn print_ref_list(kinds, detached, verbose, abbrev, with_commit, argc ? argv[0] : NULL);\n \telse if (rename && (argc == 1))\n \t\trename_branch(head, argv[0], rename > 1);\n-- \n1.7.5.270.gafca7\n"},{"id":"166529","messageId":"7vvcxz8vtj.fsf@alter.siamese.dyndns.org","threadId":"27198","inReplyTo":"cover.1303906496.git.git@drmicha.warpmail.net","subject":"Re: [RFC/PATCH 0/2] RFC/POC: patterns for branch list","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-27T17:10:00Z","receivedAt":"2011-04-27T17:10:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> This mini series is about introducing patterns to the list mode of\n> 'git branch' much like the pattern for 'git tag -l'.\n\nI do find myself often typing\n\n    git branch | grep mg/\n\nso this would be a welcome addition, even though the above is not too ugly\nnor cumbersome.\n\n> '-l' is the natural short option name for '--list'. This is taken for the\n> rarely used or needed 'create reflog' option. I'd change the latter to\n> '-g,--create-reflog' (cmp. log) and take '-l,--list' but know the reaction\n> already.\n\nMy reaction would be \"As the eventual goal, it is the right thing to\ndo---if we were writing git from scratch today, we would probably have\ndone so. Present a reasonable migration plan.\".  Perhaps like this?\n\n 1. Introduce \"--create-reflog\", and deprecate \"-l\".  Make \"branch -l\"\n    emit warning and advise to use \"--create-reflog\" instead, but still\n    act as a synonym for \"--create-reflog\".\n\n    Introduce \"--list\" but without any short option.\n\n    Ship 1.7.6 with these changes.\n\n 2. Introduce \"-g\" as synonym for \"--create-reflog\".  Make \"branch -l\" die\n    and advise to use \"-g\" or \"--create-reflog\" instead.\n\n    Ship 1.7.X series after 1.7.7 with these changes.\n\n 3. In 1.8.0, make \"-l\" a synonym for \"--list\".\n\n> '-v' and '-vv' both take considerable time (because they need to walk).\n> It makes more sense to have '-v' display cheap output (upstream name)\n> and '-vv' add expensive output (ahead/behind info). '-vvv' could add super\n> expensive info (ahead/equivalent/behind a la cherry-mark).\n\nProbably.  Would it be a solution to deprecate \"git branch -v\" and make\nthe behaviour of \"git branch -l -v{1,3}\" as you described?\n"}]}