{"thread":{"id":"45031","subject":"[PATCH 00/12] completion: speed up refs completion","startedAt":"2017-02-03T02:54:30Z","lastAt":"2017-02-13T20:24:45Z","messageCount":23,"participants":["SZEDER Gábor","Jacob Keller","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":12},"messages":[{"id":"310770","messageId":"20170203025405.8242-1-szeder.dev@gmail.com","threadId":"45031","inReplyTo":null,"subject":"[PATCH 00/12] completion: speed up refs completion","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:53:53Z","receivedAt":"2017-02-03T02:54:30Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"This series speeds up refs completion for large number of refs, partly\nby giving up disambiguating ambiguous refs (patch 6) and partly by\neliminating most of the shell processing between 'git for-each-ref'\nand 'ls-remote' and Bash's completion facility.  The rest is a bit of\npreparatory reorganization, cleanup and bugfixes.\n\nThe last patch touches the ZSH wrapper, too.  By a lucky educated\nguess I managed to get it work on the first try, but I don't really\nknow what I've actually done, so...  ZSH users, please have a closer\nlook.\n\nAt the end of this series refs completion from a local repository is\nas fast as it can possibly get, at least as far as the completion\nscript is concerned, because it basically does nothing anymore :)  All\nit does is run 'git for-each-ref' with assorted options to do all the\nwork, and feed its output directly, without any processing into Bash's\nCOMPREPLY array.  There is still room for improvements in the code\npaths using 'git ls-remote', but for that we would need enhancements\nto 'ls-remote'.\n\nIt goes on top of the __gitdir() improvements series I just posted at:\n\n  http://public-inbox.org/git/20170203024829.8071-1-szeder.dev@gmail.com/T/\n\nThis series is also available at:\n\n  https://github.com/szeder/git completion-refs-speedup\n\n\nSZEDER Gábor (12):\n  completion: remove redundant __gitcomp_nl() options from _git_commit()\n  completion: wrap __git_refs() for better option parsing\n  completion: support completing full refs after '--option=refs/<TAB>'\n  completion: support excluding full refs\n  completion: don't disambiguate tags and branches\n  completion: don't disambiguate short refs\n  completion: let 'for-each-ref' and 'ls-remote' filter matching refs\n  completion: let 'for-each-ref' strip the remote name from remote\n    branches\n  completion: let 'for-each-ref' filter remote branches for 'checkout'\n    DWIMery\n  completion: let 'for-each-ref' sort remote branches for 'checkout'\n    DWIMery\n  completion: list only matching symbolic and pseudorefs when completing\n    refs\n  completion: fill COMPREPLY directly when completing refs\n\n contrib/completion/git-completion.bash | 205 ++++++++++++++++--------\n contrib/completion/git-completion.zsh  |   9 ++\n t/t9902-completion.sh                  | 282 +++++++++++++++++++++++++++++++++\n 3 files changed, 430 insertions(+), 66 deletions(-)\n\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310771","messageId":"20170203025405.8242-2-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 01/12] completion: remove redundant __gitcomp_nl() options from _git_commit()","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:53:54Z","receivedAt":"2017-02-03T02:54:33Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Those two options are specifying the default values that\n__gitcomp_nl() would use anyway when invoked with no options at all.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ed06cb621..f20d4600c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1216,7 +1216,7 @@ _git_commit ()\n {\n \tcase \"$prev\" in\n \t-c|-C)\n-\t\t__gitcomp_nl \"$(__git_refs)\" \"\" \"${cur}\"\n+\t\t__gitcomp_nl \"$(__git_refs)\"\n \t\treturn\n \t\t;;\n \tesac\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310772","messageId":"20170203025405.8242-3-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 02/12] completion: wrap __git_refs() for better option parsing","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:53:55Z","receivedAt":"2017-02-03T02:54:36Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"__git_refs() currently accepts two optional positional parameters: a\nremote and a flag for 'git checkout's tracking DWIMery.  To fix a\nminor bug, and, more importantly, for faster refs completion, this\nseries will add three more parameters: a prefix, the current word to\nbe completed and a suffix, i.e. the options accepted by __gitcomp() &\nfriends, and will change __git_refs() to list only refs matching that\ngiven current word and to add that given prefix and suffix to the\nlisted refs.\n\nHowever, __git_refs() is the helper function that is most likely used\nin users' custom completion scriptlets for their own git commands, and\nwe don't want to break those, so\n\n  - we can't change __git_refs()'s default output format, i.e. we\n    can't by default append a trailing space to every listed ref,\n    meaning that the suffix parameter containing the default trailing\n    space would have to be specified on every invocation, and\n\n  - we can't change the position of existing positional parameters\n    either, so there would have to be plenty of set-but-empty\n    placeholder positional parameters all over the completion script.\n\nFurthermore, with five positional parameters it would be really hard\nto remember which position means what.\n\nTo keep callsites simple, add the new wrapper function\n__git_complete_refs() around __git_refs(), which:\n\n  - instead of positional parameters accepts real '--opt=val'-style\n    options and with minimalistic option parsing translates them to\n    __git_refs()'s and __gitcomp_nl()'s positional parameters, and\n\n  - includes the '__gitcomp_nl \"$(__git_refs ...)\" ...' command\n    substitution to make its behavior match its name and the behavior\n    of other __git_complete_* functions, and to limit future changes\n    in this series to __git_refs() and this new wrapper function.\n\nCall this wrapper function instead of __git_refs() wherever possible\nthroughout the completion script, i.e. when __git_refs()'s output is\nfed to __gitcomp_nl() right away without further processing, which\nmeans all callsites except a single one in the __git_refs2() helper.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 102 ++++++++++++++++++++-----------\n t/t9902-completion.sh                  | 106 +++++++++++++++++++++++++++++++++\n 2 files changed, 173 insertions(+), 35 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex f20d4600c..7f19e2a4f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -354,6 +354,8 @@ __git_tags ()\n #    Can be the name of a configured remote, a path, or a URL.\n # 2: In addition to local refs, list unique branches from refs/remotes/ for\n #    'git checkout's tracking DWIMery (optional; ignored, if set but empty).\n+#\n+# Use __git_complete_refs() instead.\n __git_refs ()\n {\n \tlocal i hash dir track=\"${2-}\"\n@@ -446,6 +448,36 @@ __git_refs ()\n \tesac\n }\n \n+# Completes refs, short and long, local and remote, symbolic and pseudo.\n+#\n+# Usage: __git_complete_refs [<option>]...\n+# --remote=<remote>: The remote to list refs from, can be the name of a\n+#                    configured remote, a path, or a URL.\n+# --track: List unique remote branches for 'git checkout's tracking DWIMery.\n+# --pfx=<prefix>: A prefix to be added to each ref.\n+# --cur=<word>: The current ref to be completed.  Defaults to the current\n+#               word to be completed.\n+# --sfx=<suffix>: A suffix to be appended to each ref instead of the default\n+#                 space.\n+__git_complete_refs ()\n+{\n+\tlocal remote track pfx cur_=\"$cur\" sfx=\" \"\n+\n+\twhile test $# != 0; do\n+\t\tcase \"$1\" in\n+\t\t--remote=*)\tremote=\"${1##--remote=}\" ;;\n+\t\t--track)\ttrack=\"yes\" ;;\n+\t\t--pfx=*)\tpfx=\"${1##--pfx=}\" ;;\n+\t\t--cur=*)\tcur_=\"${1##--cur=}\" ;;\n+\t\t--sfx=*)\tsfx=\"${1##--sfx=}\" ;;\n+\t\t*)\t\treturn 1 ;;\n+\t\tesac\n+\t\tshift\n+\tdone\n+\n+\t__gitcomp_nl \"$(__git_refs \"$remote\" \"$track\")\" \"$pfx\" \"$cur_\" \"$sfx\"\n+}\n+\n # __git_refs2 requires 1 argument (to pass to __git_refs)\n __git_refs2 ()\n {\n@@ -554,15 +586,15 @@ __git_complete_revlist_file ()\n \t*...*)\n \t\tpfx=\"${cur_%...*}...\"\n \t\tcur_=\"${cur_#*...}\"\n-\t\t__gitcomp_nl \"$(__git_refs)\" \"$pfx\" \"$cur_\"\n+\t\t__git_complete_refs --pfx=\"$pfx\" --cur=\"$cur_\"\n \t\t;;\n \t*..*)\n \t\tpfx=\"${cur_%..*}..\"\n \t\tcur_=\"${cur_#*..}\"\n-\t\t__gitcomp_nl \"$(__git_refs)\" \"$pfx\" \"$cur_\"\n+\t\t__git_complete_refs --pfx=\"$pfx\" --cur=\"$cur_\"\n \t\t;;\n \t*)\n-\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t__git_complete_refs\n \t\t;;\n \tesac\n }\n@@ -649,21 +681,21 @@ __git_complete_remote_or_refspec ()\n \t\tif [ $lhs = 1 ]; then\n \t\t\t__gitcomp_nl \"$(__git_refs2 \"$remote\")\" \"$pfx\" \"$cur_\"\n \t\telse\n-\t\t\t__gitcomp_nl \"$(__git_refs)\" \"$pfx\" \"$cur_\"\n+\t\t\t__git_complete_refs --pfx=\"$pfx\" --cur=\"$cur_\"\n \t\tfi\n \t\t;;\n \tpull|remote)\n \t\tif [ $lhs = 1 ]; then\n-\t\t\t__gitcomp_nl \"$(__git_refs \"$remote\")\" \"$pfx\" \"$cur_\"\n+\t\t\t__git_complete_refs --remote=\"$remote\" --pfx=\"$pfx\" --cur=\"$cur_\"\n \t\telse\n-\t\t\t__gitcomp_nl \"$(__git_refs)\" \"$pfx\" \"$cur_\"\n+\t\t\t__git_complete_refs --pfx=\"$pfx\" --cur=\"$cur_\"\n \t\tfi\n \t\t;;\n \tpush)\n \t\tif [ $lhs = 1 ]; then\n-\t\t\t__gitcomp_nl \"$(__git_refs)\" \"$pfx\" \"$cur_\"\n+\t\t\t__git_complete_refs --pfx=\"$pfx\" --cur=\"$cur_\"\n \t\telse\n-\t\t\t__gitcomp_nl \"$(__git_refs \"$remote\")\" \"$pfx\" \"$cur_\"\n+\t\t\t__git_complete_refs --remote=\"$remote\" --pfx=\"$pfx\" --cur=\"$cur_\"\n \t\tfi\n \t\t;;\n \tesac\n@@ -1061,7 +1093,7 @@ _git_bisect ()\n \n \tcase \"$subcommand\" in\n \tbad|good|reset|skip|start)\n-\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t__git_complete_refs\n \t\t;;\n \t*)\n \t\t;;\n@@ -1083,7 +1115,7 @@ _git_branch ()\n \n \tcase \"$cur\" in\n \t--set-upstream-to=*)\n-\t\t__gitcomp_nl \"$(__git_refs)\" \"\" \"${cur##--set-upstream-to=}\"\n+\t\t__git_complete_refs --cur=\"${cur##--set-upstream-to=}\"\n \t\t;;\n \t--*)\n \t\t__gitcomp \"\n@@ -1097,7 +1129,7 @@ _git_branch ()\n \t\tif [ $only_local_ref = \"y\" -a $has_r = \"n\" ]; then\n \t\t\t__gitcomp_nl \"$(__git_heads)\"\n \t\telse\n-\t\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t\t__git_complete_refs\n \t\tfi\n \t\t;;\n \tesac\n@@ -1140,18 +1172,18 @@ _git_checkout ()\n \t*)\n \t\t# check if --track, --no-track, or --no-guess was specified\n \t\t# if so, disable DWIM mode\n-\t\tlocal flags=\"--track --no-track --no-guess\" track=1\n+\t\tlocal flags=\"--track --no-track --no-guess\" track_opt=\"--track\"\n \t\tif [ -n \"$(__git_find_on_cmdline \"$flags\")\" ]; then\n-\t\t\ttrack=''\n+\t\t\ttrack_opt=''\n \t\tfi\n-\t\t__gitcomp_nl \"$(__git_refs '' $track)\"\n+\t\t__git_complete_refs $track_opt\n \t\t;;\n \tesac\n }\n \n _git_cherry ()\n {\n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n _git_cherry_pick ()\n@@ -1166,7 +1198,7 @@ _git_cherry_pick ()\n \t\t__gitcomp \"--edit --no-commit --signoff --strategy= --mainline\"\n \t\t;;\n \t*)\n-\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t__git_complete_refs\n \t\t;;\n \tesac\n }\n@@ -1216,7 +1248,7 @@ _git_commit ()\n {\n \tcase \"$prev\" in\n \t-c|-C)\n-\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t__git_complete_refs\n \t\treturn\n \t\t;;\n \tesac\n@@ -1229,7 +1261,7 @@ _git_commit ()\n \t\t;;\n \t--reuse-message=*|--reedit-message=*|\\\n \t--fixup=*|--squash=*)\n-\t\t__gitcomp_nl \"$(__git_refs)\" \"\" \"${cur#*=}\"\n+\t\t__git_complete_refs --cur=\"${cur#*=}\"\n \t\treturn\n \t\t;;\n \t--untracked-files=*)\n@@ -1267,7 +1299,7 @@ _git_describe ()\n \t\t\t\"\n \t\treturn\n \tesac\n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n __git_diff_algorithms=\"myers minimal patience histogram\"\n@@ -1453,7 +1485,7 @@ _git_grep ()\n \t\t;;\n \tesac\n \n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n _git_help ()\n@@ -1621,7 +1653,7 @@ _git_merge ()\n \t\t\t--rerere-autoupdate --no-rerere-autoupdate --abort --continue\"\n \t\treturn\n \tesac\n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n _git_mergetool ()\n@@ -1646,7 +1678,7 @@ _git_merge_base ()\n \t\treturn\n \t\t;;\n \tesac\n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n _git_mv ()\n@@ -1684,7 +1716,7 @@ _git_notes ()\n \t,*)\n \t\tcase \"$prev\" in\n \t\t--ref)\n-\t\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t\t__git_complete_refs\n \t\t\t;;\n \t\t*)\n \t\t\t__gitcomp \"$subcommands --ref\"\n@@ -1693,7 +1725,7 @@ _git_notes ()\n \t\t;;\n \tadd,--reuse-message=*|append,--reuse-message=*|\\\n \tadd,--reedit-message=*|append,--reedit-message=*)\n-\t\t__gitcomp_nl \"$(__git_refs)\" \"\" \"${cur#*=}\"\n+\t\t__git_complete_refs --cur=\"${cur#*=}\"\n \t\t;;\n \tadd,--*|append,--*)\n \t\t__gitcomp '--file= --message= --reedit-message=\n@@ -1712,7 +1744,7 @@ _git_notes ()\n \t\t-m|-F)\n \t\t\t;;\n \t\t*)\n-\t\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t\t__git_complete_refs\n \t\t\t;;\n \t\tesac\n \t\t;;\n@@ -1750,10 +1782,10 @@ __git_complete_force_with_lease ()\n \t--*=)\n \t\t;;\n \t*:*)\n-\t\t__gitcomp_nl \"$(__git_refs)\" \"\" \"${cur_#*:}\"\n+\t\t__git_complete_refs --cur=\"${cur_#*:}\"\n \t\t;;\n \t*)\n-\t\t__gitcomp_nl \"$(__git_refs)\" \"\" \"$cur_\"\n+\t\t__git_complete_refs --cur=\"$cur_\"\n \t\t;;\n \tesac\n }\n@@ -1829,7 +1861,7 @@ _git_rebase ()\n \n \t\treturn\n \tesac\n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n _git_reflog ()\n@@ -1840,7 +1872,7 @@ _git_reflog ()\n \tif [ -z \"$subcommand\" ]; then\n \t\t__gitcomp \"$subcommands\"\n \telse\n-\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t__git_complete_refs\n \tfi\n }\n \n@@ -1986,7 +2018,7 @@ _git_config ()\n \t\treturn\n \t\t;;\n \tbranch.*.merge)\n-\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t__git_complete_refs\n \t\treturn\n \t\t;;\n \tbranch.*.rebase)\n@@ -2460,7 +2492,7 @@ _git_remote ()\n \n _git_replace ()\n {\n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n _git_reset ()\n@@ -2473,7 +2505,7 @@ _git_reset ()\n \t\treturn\n \t\t;;\n \tesac\n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n _git_revert ()\n@@ -2489,7 +2521,7 @@ _git_revert ()\n \t\treturn\n \t\t;;\n \tesac\n-\t__gitcomp_nl \"$(__git_refs)\"\n+\t__git_complete_refs\n }\n \n _git_rm ()\n@@ -2597,7 +2629,7 @@ _git_stash ()\n \t\t\t;;\n \t\tbranch,*)\n \t\t\tif [ $cword -eq 3 ]; then\n-\t\t\t\t__gitcomp_nl \"$(__git_refs)\";\n+\t\t\t\t__git_complete_refs\n \t\t\telse\n \t\t\t\t__gitcomp_nl \"$(__git stash list \\\n \t\t\t\t\t\t| sed -n -e 's/:.*//p')\"\n@@ -2755,7 +2787,7 @@ _git_tag ()\n \t\tfi\n \t\t;;\n \t*)\n-\t\t__gitcomp_nl \"$(__git_refs)\"\n+\t\t__git_complete_refs\n \t\t;;\n \tesac\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex d711bef24..50c534072 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -775,6 +775,112 @@ test_expect_success '__git_refs - unique remote branches for git checkout DWIMer\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success '__git_complete_refs - simple' '\n+\tsed -e \"s/Z$//g\" >expected <<-EOF &&\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tmatching-tag Z\n+\tEOF\n+\t(\n+\t\tcur= &&\n+\t\t__git_complete_refs &&\n+\t\tprint_comp\n+\t) &&\n+\ttest_cmp expected out\n+'\n+\n+test_expect_success '__git_complete_refs - matching' '\n+\tsed -e \"s/Z$//g\" >expected <<-EOF &&\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tEOF\n+\t(\n+\t\tcur=mat &&\n+\t\t__git_complete_refs &&\n+\t\tprint_comp\n+\t) &&\n+\ttest_cmp expected out\n+'\n+\n+test_expect_success '__git_complete_refs - remote' '\n+\tsed -e \"s/Z$//g\" >expected <<-EOF &&\n+\tHEAD Z\n+\tbranch-in-other Z\n+\tmaster-in-other Z\n+\tEOF\n+\t(\n+\t\tcur=\n+\t\t__git_complete_refs --remote=other &&\n+\t\tprint_comp\n+\t) &&\n+\ttest_cmp expected out\n+'\n+\n+test_expect_success '__git_complete_refs - track' '\n+\tsed -e \"s/Z$//g\" >expected <<-EOF &&\n+\tHEAD Z\n+\tmaster Z\n+\tmatching-branch Z\n+\tother/branch-in-other Z\n+\tother/master-in-other Z\n+\tmatching-tag Z\n+\tbranch-in-other Z\n+\tmaster-in-other Z\n+\tEOF\n+\t(\n+\t\tcur=\n+\t\t__git_complete_refs --track &&\n+\t\tprint_comp\n+\t) &&\n+\ttest_cmp expected out\n+'\n+\n+test_expect_success '__git_complete_refs - current word' '\n+\tsed -e \"s/Z$//g\" >expected <<-EOF &&\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tEOF\n+\t(\n+\t\tcur=\"--option=mat\" &&\n+\t\t__git_complete_refs --cur=\"${cur#*=}\" &&\n+\t\tprint_comp\n+\t) &&\n+\ttest_cmp expected out\n+'\n+\n+test_expect_success '__git_complete_refs - prefix' '\n+\tsed -e \"s/Z$//g\" >expected <<-EOF &&\n+\tv1.0..matching-branch Z\n+\tv1.0..matching-tag Z\n+\tEOF\n+\t(\n+\t\tcur=v1.0..mat &&\n+\t\t__git_complete_refs --pfx=v1.0.. --cur=mat &&\n+\t\tprint_comp\n+\t) &&\n+\ttest_cmp expected out\n+'\n+\n+test_expect_success '__git_complete_refs - suffix' '\n+\tcat >expected <<-EOF &&\n+\tHEAD.\n+\tmaster.\n+\tmatching-branch.\n+\tother/branch-in-other.\n+\tother/master-in-other.\n+\tmatching-tag.\n+\tEOF\n+\t(\n+\t\tcur= &&\n+\t\t__git_complete_refs --sfx=. &&\n+\t\tprint_comp\n+\t) &&\n+\ttest_cmp expected out\n+'\n+\n test_expect_success 'teardown after ref completion' '\n \tgit branch -d matching-branch &&\n \tgit tag -d matching-tag &&\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310773","messageId":"20170203025405.8242-8-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 07/12] completion: let 'for-each-ref' and 'ls-remote' filter matching refs","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:54:00Z","receivedAt":"2017-02-03T02:54:39Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"When completing refs, several __git_refs() code paths list all the\nrefs from the refs/{heads,tags,remotes}/ hierarchy and then\n__gitcomp_nl() iterates over those refs in a shell loop to filter out\nrefs not matching the current word to be completed.  This comes with a\nconsiderable performance penalty when a repository contains a lot of\nrefs but the current word can be uniquely completed or when only a\nhandful of refs match the current word.\n\nSpecify appropriate globbing patterns to 'git for-each-ref' and 'git\nls-remote' to list only those refs that match the current word to be\ncompleted.  This reduces the number of iterations in __gitcomp_nl()\nfrom the number of refs to the number of matching refs.\n\nThis speeds up refs completion considerably when there are a lot of\nnon-matching refs to be filtered out.  Uniquely completing a branch in\na repository with 100k local branches, all packed, best of five:\n\n  On Linux, before:\n\n    $ time __git_complete_refs --cur=maste\n\n    real    0m0.831s\n    user    0m0.808s\n    sys     0m0.028s\n\n  After:\n\n    real    0m0.119s\n    user    0m0.104s\n    sys     0m0.008s\n\n  On Windows, before:\n\n    real    0m1.480s\n    user    0m1.031s\n    sys     0m0.060s\n\n  After:\n\n    real    0m0.377s\n    user    0m0.015s\n    sys     0m0.030s\n\nStrictly speaking this is a fundamental behavior change in\n__git_refs(), a helper function that is likely used in users' custom\ncompletion scriptlets.  However, arguably this change should be\nharmless, because:\n\n  - __git_refs() was only ever intended to feed refs to Bash's\n    completion machinery, for which non-matching refs have to be\n    filtered out anyway.\n\n  - There were already code paths that list only matching refs\n    (listing unique remote branches for 'git checkout's tracking\n    DWIMery and listing full remote refs via 'git ls-remote').\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash |  14 +++--\n t/t9902-completion.sh                  | 102 +++++++++++++++++++++++++++++++++\n 2 files changed, 111 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex d55eadfd1..615292f8b 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -394,7 +394,7 @@ __git_refs ()\n \t\tcase \"$cur_\" in\n \t\trefs|refs/*)\n \t\t\tformat=\"refname\"\n-\t\t\trefs=\"${cur_%/*}\"\n+\t\t\trefs=(\"$cur_*\" \"$cur_*/**\")\n \t\t\ttrack=\"\"\n \t\t\t;;\n \t\t*)\n@@ -402,11 +402,13 @@ __git_refs ()\n \t\t\t\tif [ -e \"$dir/$i\" ]; then echo $pfx$i; fi\n \t\t\tdone\n \t\t\tformat=\"refname:strip=2\"\n-\t\t\trefs=\"refs/tags refs/heads refs/remotes\"\n+\t\t\trefs=(\"refs/tags/$cur_*\" \"refs/tags/$cur_*/**\"\n+\t\t\t\t\"refs/heads/$cur_*\" \"refs/heads/$cur_*/**\"\n+\t\t\t\t\"refs/remotes/$cur_*\" \"refs/remotes/$cur_*/**\")\n \t\t\t;;\n \t\tesac\n \t\t__git_dir=\"$dir\" __git for-each-ref --format=\"$pfx%($format)\" \\\n-\t\t\t$refs\n+\t\t\t\"${refs[@]}\"\n \t\tif [ -n \"$track\" ]; then\n \t\t\t# employ the heuristic used by git checkout\n \t\t\t# Try to find a remote branch that matches the completion word\n@@ -438,10 +440,12 @@ __git_refs ()\n \t\tif [ \"$list_refs_from\" = remote ]; then\n \t\t\techo \"HEAD\"\n \t\t\t__git for-each-ref --format=\"%(refname:strip=2)\" \\\n-\t\t\t\t\"refs/remotes/$remote/\" | sed -e \"s#^$remote/##\"\n+\t\t\t\t\"refs/remotes/$remote/$cur_*\" \\\n+\t\t\t\t\"refs/remotes/$remote/$cur_*/**\" | sed -e \"s#^$remote/##\"\n \t\telse\n \t\t\t__git ls-remote \"$remote\" HEAD \\\n-\t\t\t\t\"refs/tags/*\" \"refs/heads/*\" \"refs/remotes/*\" |\n+\t\t\t\t\"refs/tags/$cur_*\" \"refs/heads/$cur_*\" \\\n+\t\t\t\t\"refs/remotes/$cur_*\" |\n \t\t\twhile read -r hash i; do\n \t\t\t\tcase \"$i\" in\n \t\t\t\t*^{})\t;;\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 7b42a686c..499be5879 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -837,6 +837,108 @@ test_expect_success '__git refs - exluding full refs' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success 'setup for filtering matching refs' '\n+\tgit branch matching/branch &&\n+\tgit tag matching/tag &&\n+\tgit -C otherrepo branch matching/branch-in-other &&\n+\tgit fetch --no-tags other &&\n+\trm -f .git/FETCH_HEAD\n+'\n+\n+test_expect_success '__git_refs - only matching refs' '\n+\tcat >expected <<-EOF &&\n+\tHEAD\n+\tmatching-branch\n+\tmatching/branch\n+\tmatching-tag\n+\tmatching/tag\n+\tEOF\n+\t(\n+\t\tcur=mat &&\n+\t\t__git_refs >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success '__git_refs - only matching refs - full refs' '\n+\tcat >expected <<-EOF &&\n+\trefs/heads/matching-branch\n+\trefs/heads/matching/branch\n+\tEOF\n+\t(\n+\t\tcur=refs/heads/mat &&\n+\t\t__git_refs >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success '__git_refs - only matching refs - remote on local file system' '\n+\tcat >expected <<-EOF &&\n+\tHEAD\n+\tmaster-in-other\n+\tmatching/branch-in-other\n+\tEOF\n+\t(\n+\t\tcur=ma &&\n+\t\t__git_refs otherrepo >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success '__git_refs - only matching refs - configured remote' '\n+\tcat >expected <<-EOF &&\n+\tHEAD\n+\tmaster-in-other\n+\tmatching/branch-in-other\n+\tEOF\n+\t(\n+\t\tcur=ma &&\n+\t\t__git_refs other >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success '__git_refs - only matching refs - remote - full refs' '\n+\tcat >expected <<-EOF &&\n+\trefs/heads/master-in-other\n+\trefs/heads/matching/branch-in-other\n+\tEOF\n+\t(\n+\t\tcur=refs/heads/ma &&\n+\t\t__git_refs other >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success '__git_refs - only matching refs - checkout DWIMery' '\n+\tcat >expected <<-EOF &&\n+\tHEAD\n+\tmatching-branch\n+\tmatching/branch\n+\tmatching-tag\n+\tmatching/tag\n+\tmatching/branch-in-other\n+\tEOF\n+\tfor remote_ref in refs/remotes/other/ambiguous \\\n+\t\trefs/remotes/remote/ambiguous \\\n+\t\trefs/remotes/remote/branch-in-remote\n+\tdo\n+\t\tgit update-ref $remote_ref master &&\n+\t\ttest_when_finished \"git update-ref -d $remote_ref\"\n+\tdone &&\n+\t(\n+\t\tcur=mat &&\n+\t\t__git_refs \"\" 1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'teardown after filtering matching refs' '\n+\tgit branch -d matching/branch &&\n+\tgit tag -d matching/tag &&\n+\tgit update-ref -d refs/remotes/other/matching/branch-in-other\n+'\n+\n test_expect_success '__git_complete_refs - simple' '\n \tsed -e \"s/Z$//g\" >expected <<-EOF &&\n \tHEAD Z\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310774","messageId":"20170203025405.8242-4-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 03/12] completion: support completing full refs after '--option=refs/<TAB>'","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:53:56Z","receivedAt":"2017-02-03T02:54:42Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Completing full refs currently only works when the full ref stands on\nin its own on the command line, but doesn't work when the current word\nto be completed contains a prefix before the full ref, e.g.\n'--option=refs/<TAB>' or 'master..refs/bis<TAB>'.\n\nThe reason is that __git_refs() looks at the current word to be\ncompleted ($cur) as a whole to decide whether it has to list full (if\nit starts with 'refs/') or short refs (otherwise).  However, $cur also\nholds said '--option=' or 'master..' prefixes, which of course throw\noff this decision.  Luckily, the default action is to list short refs,\nthat's why completing short refs happens to work even after a\n'master..<TAB>' prefix and similar cases.\n\nPass only the ref part of the current word to be completed to\n__git_refs() as a new positional parameter, so it can make the right\ndecision even if the whole current word contains some kind of a\nprefix.\n\nMake this new parameter the 4. positional parameter and leave the 3.\nas an ignored placeholder for now (it will be used later in this patch\nseries).\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 21 ++++++++++++++-------\n t/t9902-completion.sh                  | 31 +++++++++++++++++++++++++++++++\n 2 files changed, 45 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 7f19e2a4f..67a03cfd4 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -354,6 +354,8 @@ __git_tags ()\n #    Can be the name of a configured remote, a path, or a URL.\n # 2: In addition to local refs, list unique branches from refs/remotes/ for\n #    'git checkout's tracking DWIMery (optional; ignored, if set but empty).\n+# 3: Currently ignored.\n+# 4: The current ref to be completed (optional).\n #\n # Use __git_complete_refs() instead.\n __git_refs ()\n@@ -361,6 +363,7 @@ __git_refs ()\n \tlocal i hash dir track=\"${2-}\"\n \tlocal list_refs_from=path remote=\"${1-}\"\n \tlocal format refs pfx\n+\tlocal cur_=\"${4-$cur}\"\n \n \t__git_find_repo_path\n \tdir=\"$__git_repo_path\"\n@@ -384,14 +387,17 @@ __git_refs ()\n \tfi\n \n \tif [ \"$list_refs_from\" = path ]; then\n-\t\tcase \"$cur\" in\n+\t\tcase \"$cur_\" in\n \t\trefs|refs/*)\n \t\t\tformat=\"refname\"\n-\t\t\trefs=\"${cur%/*}\"\n+\t\t\trefs=\"${cur_%/*}\"\n \t\t\ttrack=\"\"\n \t\t\t;;\n \t\t*)\n-\t\t\t[[ \"$cur\" == ^* ]] && pfx=\"^\"\n+\t\t\tif [[ \"$cur_\" == ^* ]]; then\n+\t\t\t\tpfx=\"^\"\n+\t\t\t\tcur_=${cur_#^}\n+\t\t\tfi\n \t\t\tfor i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do\n \t\t\t\tif [ -e \"$dir/$i\" ]; then echo $pfx$i; fi\n \t\t\tdone\n@@ -411,16 +417,16 @@ __git_refs ()\n \t\t\twhile read -r entry; do\n \t\t\t\teval \"$entry\"\n \t\t\t\tref=\"${ref#*/}\"\n-\t\t\t\tif [[ \"$ref\" == \"$cur\"* ]]; then\n+\t\t\t\tif [[ \"$ref\" == \"$cur_\"* ]]; then\n \t\t\t\t\techo \"$ref\"\n \t\t\t\tfi\n \t\t\tdone | sort | uniq -u\n \t\tfi\n \t\treturn\n \tfi\n-\tcase \"$cur\" in\n+\tcase \"$cur_\" in\n \trefs|refs/*)\n-\t\t__git ls-remote \"$remote\" \"$cur*\" | \\\n+\t\t__git ls-remote \"$remote\" \"$cur_*\" | \\\n \t\twhile read -r hash i; do\n \t\t\tcase \"$i\" in\n \t\t\t*^{}) ;;\n@@ -475,7 +481,8 @@ __git_complete_refs ()\n \t\tshift\n \tdone\n \n-\t__gitcomp_nl \"$(__git_refs \"$remote\" \"$track\")\" \"$pfx\" \"$cur_\" \"$sfx\"\n+\t__gitcomp_nl \"$(__git_refs \"$remote\" \"$track\" \"\" \"$cur_\")\" \\\n+\t\t\"$pfx\" \"$cur_\" \"$sfx\"\n }\n \n # __git_refs2 requires 1 argument (to pass to __git_refs)\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 50c534072..8fe748839 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -775,6 +775,37 @@ test_expect_success '__git_refs - unique remote branches for git checkout DWIMer\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success '__git_refs - after --opt=' '\n+\tcat >expected <<-EOF &&\n+\tHEAD\n+\tmaster\n+\tmatching-branch\n+\tother/branch-in-other\n+\tother/master-in-other\n+\tmatching-tag\n+\tEOF\n+\t(\n+\t\tcur=\"--opt=\" &&\n+\t\t__git_refs \"\" \"\" \"\" \"\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success '__git_refs - after --opt= - full refs' '\n+\tcat >expected <<-EOF &&\n+\trefs/heads/master\n+\trefs/heads/matching-branch\n+\trefs/remotes/other/branch-in-other\n+\trefs/remotes/other/master-in-other\n+\trefs/tags/matching-tag\n+\tEOF\n+\t(\n+\t\tcur=\"--opt=refs/\" &&\n+\t\t__git_refs \"\" \"\" \"\" refs/ >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_expect_success '__git_complete_refs - simple' '\n \tsed -e \"s/Z$//g\" >expected <<-EOF &&\n \tHEAD Z\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310775","messageId":"20170203025405.8242-9-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 08/12] completion: let 'for-each-ref' strip the remote name from remote branches","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:54:01Z","receivedAt":"2017-02-03T02:54:43Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"The code listing unique remote branches for 'git checkout's tracking\nDWIMery uses a shell parameter expansion in a loop iterating over each\nlisted ref to remove the remote's name from the remote branches, i.e.\nthe leading path component from the short ref.  When listing refs from\na configured remote repository, '| sed s///' is used for the same\npurpose.\n\nLet 'git for-each-ref' strip one more leading path component from the\nrefs, i.e. use the format 'refname:strip=3' instead of '=2', making\nthat parameter expansion and 'sed' execution unnecessary.\n\nThis speeds up refs completion for 'git checkout'.  Uniquely\ncompleting a branch for 'git checkout maste<TAB>' in a repo with 100k\nremote branches, all packed, best of five:\n\n  On Linux, near the beginning of this series, for reference:\n\n    $ time __git_complete_refs --cur=maste --track\n\n    real    0m8.185s\n    user    0m6.896s\n    sys     0m1.616s\n\n  Before this patch:\n\n    real    0m2.714s\n    user    0m2.344s\n    sys     0m0.436s\n\n  After:\n\n    real    0m1.993s\n    user    0m1.740s\n    sys     0m0.304s\n\n  On Windows, near the beginning:\n\n    real    1m8.421s\n    user    0m7.591s\n    sys     0m3.557s\n\n  Before this patch:\n\n    real    0m8.191s\n    user    0m4.638s\n    sys     0m2.918s\n\n  After:\n\n    real    0m6.187s\n    user    0m3.358s\n    sys     0m2.121s\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 615292f8b..8f1203025 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -414,11 +414,10 @@ __git_refs ()\n \t\t\t# Try to find a remote branch that matches the completion word\n \t\t\t# but only output if the branch name is unique\n \t\t\tlocal ref entry\n-\t\t\t__git for-each-ref --shell --format=\"ref=%(refname:strip=2)\" \\\n+\t\t\t__git for-each-ref --shell --format=\"ref=%(refname:strip=3)\" \\\n \t\t\t\t\"refs/remotes/\" | \\\n \t\t\twhile read -r entry; do\n \t\t\t\teval \"$entry\"\n-\t\t\t\tref=\"${ref#*/}\"\n \t\t\t\tif [[ \"$ref\" == \"$cur_\"* ]]; then\n \t\t\t\t\techo \"$ref\"\n \t\t\t\tfi\n@@ -439,9 +438,9 @@ __git_refs ()\n \t*)\n \t\tif [ \"$list_refs_from\" = remote ]; then\n \t\t\techo \"HEAD\"\n-\t\t\t__git for-each-ref --format=\"%(refname:strip=2)\" \\\n+\t\t\t__git for-each-ref --format=\"%(refname:strip=3)\" \\\n \t\t\t\t\"refs/remotes/$remote/$cur_*\" \\\n-\t\t\t\t\"refs/remotes/$remote/$cur_*/**\" | sed -e \"s#^$remote/##\"\n+\t\t\t\t\"refs/remotes/$remote/$cur_*/**\"\n \t\telse\n \t\t\t__git ls-remote \"$remote\" HEAD \\\n \t\t\t\t\"refs/tags/$cur_*\" \"refs/heads/$cur_*\" \\\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310776","messageId":"20170203025405.8242-13-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 12/12] completion: fill COMPREPLY directly when completing refs","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:54:05Z","receivedAt":"2017-02-03T02:54:46Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"__gitcomp_nl() iterates over all the possible completion words it gets\nas argument\n\n  - filtering matching words,\n  - appending a trailing space to each matching word (in all but two\n    cases),\n  - prepending a prefix to each matching word (when completing words\n    after e.g. '--option=<TAB>' or 'master..<TAB>'), and\n  - adding each matching word to the COMPREPLY array.\n\nThis takes a while when a lot of refs are passed to __gitcomp_nl().\n\nThe previous changes in this series ensure that __git_refs() lists\nonly refs matching the current word to be completed, making a second\nfiltering in __gitcomp_nl() redundant.\n\nAdding the necessary prefix and suffix could be done in __git_refs()\nas well:\n\n  - When refs come from 'git for-each-ref', then that prefix and\n    suffix could be added much more efficiently using a 'git\n    for-each-ref' format containing said prefix and suffix.\n  - When refs come from 'git ls-remote', then that prefix and suffix\n    can be added in the shell loop that has to process 'git\n    ls-remote's output anyway.\n  - Finally, the prefix and suffix can be added to that handful of\n    potentially matching symbolic and pseudo refs right away in the\n    shell loop listing them.\n\nAnd then all what is still left to do is to assign a bunch of\nnewline-separated words to a shell array, which can be done without a\nshell loop iterating over each word, basically making all of\n__gitcomp_nl() unnecessary for refs completion.\n\nAdd the helper function __gitcomp_direct() to fill the COMPREPLY array\nwith prefiltered and preprocessed words without any additional\nprocessing, without a shell loop, with just one single compound\nassignment.  Modify __git_refs() to accept prefix and suffix\nparameters and add them to each and every listed ref.  Modify\n__git_complete_refs() to pass the prefix and suffix parameters to\n__git_refs() and to feed __git_refs()'s output to __gitcomp_direct()\ninstead of __gitcomp_nl().\n\nThis speeds up refs completion when there are a lot of refs matching\nthe current word to be completed.  Listing all branches for completion\nin a repo with 100k local branches, all packed, best of five:\n\n  On Linux, near the beginning of this series, for reference:\n\n    $ time __git_complete_refs\n\n    real    0m2.028s\n    user    0m1.692s\n    sys     0m0.344s\n\n  Before this patch:\n\n    real    0m1.135s\n    user    0m1.112s\n    sys     0m0.024s\n\n  After:\n\n    real    0m0.367s\n    user    0m0.352s\n    sys     0m0.020s\n\n  On Windows, near the beginning:\n\n    real    0m13.078s\n    user    0m1.609s\n    sys     0m0.060s\n\n  Before this patch:\n\n    real    0m2.093s\n    user    0m1.641s\n    sys     0m0.060s\n\n  After:\n\n    real    0m0.683s\n    user    0m0.203s\n    sys     0m0.076s\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 54 ++++++++++++++++++++++++----------\n contrib/completion/git-completion.zsh  |  9 ++++++\n t/t9902-completion.sh                  | 16 ++++++++++\n 3 files changed, 64 insertions(+), 15 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0ad02cec6..dbbb62f5f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -213,6 +213,20 @@ _get_comp_words_by_ref ()\n }\n fi\n \n+# Fills the COMPREPLY array with prefiltered words without any additional\n+# processing.\n+# Callers must take care of providing only words that match the current word\n+# to be completed and adding any prefix and/or suffix (trailing space!), if\n+# necessary.\n+# 1: List of newline-separated matching completion words, complete with\n+#    prefix and suffix.\n+__gitcomp_direct ()\n+{\n+\tlocal IFS=$'\\n'\n+\n+\tCOMPREPLY=($1)\n+}\n+\n __gitcompappend ()\n {\n \tlocal x i=${#COMPREPLY[@]}\n@@ -354,17 +368,19 @@ __git_tags ()\n #    Can be the name of a configured remote, a path, or a URL.\n # 2: In addition to local refs, list unique branches from refs/remotes/ for\n #    'git checkout's tracking DWIMery (optional; ignored, if set but empty).\n-# 3: Currently ignored.\n+# 3: A prefix to be added to each listed ref (optional).\n # 4: List only refs matching this word instead of the current word being\n-#    completed (optional).\n+#    completed (optional; NOT ignored, if empty, but lists all refs).\n+# 5: A suffix to be appended to each listed ref (optional; ignored, if set\n+#    but empty).\n #\n # Use __git_complete_refs() instead.\n __git_refs ()\n {\n \tlocal i hash dir track=\"${2-}\"\n \tlocal list_refs_from=path remote=\"${1-}\"\n-\tlocal format refs pfx\n-\tlocal cur_=\"${4-$cur}\"\n+\tlocal format refs\n+\tlocal pfx=\"${3-}\" cur_=\"${4-$cur}\" sfx=\"${5-}\"\n \n \t__git_find_repo_path\n \tdir=\"$__git_repo_path\"\n@@ -389,7 +405,7 @@ __git_refs ()\n \n \tif [ \"$list_refs_from\" = path ]; then\n \t\tif [[ \"$cur_\" == ^* ]]; then\n-\t\t\tpfx=\"^\"\n+\t\t\tpfx=\"$pfx^\"\n \t\t\tcur_=${cur_#^}\n \t\tfi\n \t\tcase \"$cur_\" in\n@@ -402,7 +418,7 @@ __git_refs ()\n \t\t\tfor i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do\n \t\t\t\tcase \"$i\" in\n \t\t\t\t$cur_*)\tif [ -e \"$dir/$i\" ]; then\n-\t\t\t\t\t\techo $pfx$i\n+\t\t\t\t\t\techo \"$pfx$i$sfx\"\n \t\t\t\t\tfi\n \t\t\t\t\t;;\n \t\t\t\tesac\n@@ -413,13 +429,13 @@ __git_refs ()\n \t\t\t\t\"refs/remotes/$cur_*\" \"refs/remotes/$cur_*/**\")\n \t\t\t;;\n \t\tesac\n-\t\t__git_dir=\"$dir\" __git for-each-ref --format=\"$pfx%($format)\" \\\n+\t\t__git_dir=\"$dir\" __git for-each-ref --format=\"$pfx%($format)$sfx\" \\\n \t\t\t\"${refs[@]}\"\n \t\tif [ -n \"$track\" ]; then\n \t\t\t# employ the heuristic used by git checkout\n \t\t\t# Try to find a remote branch that matches the completion word\n \t\t\t# but only output if the branch name is unique\n-\t\t\t__git for-each-ref --format=\"%(refname:strip=3)\" \\\n+\t\t\t__git for-each-ref --format=\"$pfx%(refname:strip=3)$sfx\" \\\n \t\t\t\t--sort=\"refname:strip=3\" \\\n \t\t\t\t\"refs/remotes/*/$cur_*\" \"refs/remotes/*/$cur_*/**\" | \\\n \t\t\tuniq -u\n@@ -432,16 +448,16 @@ __git_refs ()\n \t\twhile read -r hash i; do\n \t\t\tcase \"$i\" in\n \t\t\t*^{}) ;;\n-\t\t\t*) echo \"$i\" ;;\n+\t\t\t*) echo \"$pfx$i$sfx\" ;;\n \t\t\tesac\n \t\tdone\n \t\t;;\n \t*)\n \t\tif [ \"$list_refs_from\" = remote ]; then\n \t\t\tcase \"HEAD\" in\n-\t\t\t$cur_*)\techo \"HEAD\" ;;\n+\t\t\t$cur_*)\techo \"${pfx}HEAD$sfx\" ;;\n \t\t\tesac\n-\t\t\t__git for-each-ref --format=\"%(refname:strip=3)\" \\\n+\t\t\t__git for-each-ref --format=\"$pfx%(refname:strip=3)$sfx\" \\\n \t\t\t\t\"refs/remotes/$remote/$cur_*\" \\\n \t\t\t\t\"refs/remotes/$remote/$cur_*/**\"\n \t\telse\n@@ -455,8 +471,8 @@ __git_refs ()\n \t\t\twhile read -r hash i; do\n \t\t\t\tcase \"$i\" in\n \t\t\t\t*^{})\t;;\n-\t\t\t\trefs/*)\techo \"${i#refs/*/}\" ;;\n-\t\t\t\t*)\techo \"$i\" ;;  # symbolic refs\n+\t\t\t\trefs/*)\techo \"$pfx${i#refs/*/}$sfx\" ;;\n+\t\t\t\t*)\techo \"$pfx$i$sfx\" ;;  # symbolic refs\n \t\t\t\tesac\n \t\t\tdone\n \t\tfi\n@@ -491,8 +507,7 @@ __git_complete_refs ()\n \t\tshift\n \tdone\n \n-\t__gitcomp_nl \"$(__git_refs \"$remote\" \"$track\" \"\" \"$cur_\")\" \\\n-\t\t\"$pfx\" \"$cur_\" \"$sfx\"\n+\t__gitcomp_direct \"$(__git_refs \"$remote\" \"$track\" \"$pfx\" \"$cur_\" \"$sfx\")\"\n }\n \n # __git_refs2 requires 1 argument (to pass to __git_refs)\n@@ -2975,6 +2990,15 @@ if [[ -n ${ZSH_VERSION-} ]]; then\n \t\tesac\n \t}\n \n+\t__gitcomp_direct ()\n+\t{\n+\t\temulate -L zsh\n+\n+\t\tlocal IFS=$'\\n'\n+\t\tcompset -P '*[=:]'\n+\t\tcompadd -Q -- ${=1} && _ret=0\n+\t}\n+\n \t__gitcomp_nl ()\n \t{\n \t\temulate -L zsh\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex e25541308..c3521fbfc 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -67,6 +67,15 @@ __gitcomp ()\n \tesac\n }\n \n+__gitcomp_direct ()\n+{\n+\temulate -L zsh\n+\n+\tlocal IFS=$'\\n'\n+\tcompset -P '*[=:]'\n+\tcompadd -Q -- ${=1} && _ret=0\n+}\n+\n __gitcomp_nl ()\n {\n \temulate -L zsh\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 5e06acc17..1206a38ed 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -400,6 +400,22 @@ test_expect_success '__gitdir - remote as argument' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '\n+\tsed -e \"s/Z$//g\" >expected <<-EOF &&\n+\twith-trailing-space Z\n+\twithout-trailing-spaceZ\n+\t--option Z\n+\t--option=Z\n+\t$invalid_variable_name Z\n+\tEOF\n+\t(\n+\t\tcur=should_be_ignored &&\n+\t\t__gitcomp_direct \"$(cat expected)\" &&\n+\t\tprint_comp\n+\t) &&\n+\ttest_cmp expected out\n+'\n+\n test_expect_success '__gitcomp - trailing space - options' '\n \ttest_gitcomp \"--re\" \"--dry-run --reuse-message= --reedit-message=\n \t\t--reset-author\" <<-EOF\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310777","messageId":"20170203025405.8242-11-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 10/12] completion: let 'for-each-ref' sort remote branches for 'checkout' DWIMery","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:54:03Z","receivedAt":"2017-02-03T02:54:50Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"When listing unique remote branches for 'git checkout's tracking\nDWIMery, __git_refs() runs the classic '... |sort |uniq -u' pattern to\nfilter out duplicate remote branches.\n\nLet 'git for-each-ref' do the sorting, sparing the overhead of\nfork()+exec()ing 'sort' and a stage in the pipeline where potentially\nrelatively large amount of data can be passed between two subsequent\npipeline stages.\n\nThis speeds up refs completion for 'git checkout' a bit when a lot of\nremote branches match the current word to be completed.  Listing a\nsingle local and 100k remote branches, all packed, best of five:\n\n  On Linux, before:\n\n    $ time __git_complete_refs --track\n\n    real    0m1.856s\n    user    0m1.816s\n    sys     0m0.060s\n\n  After:\n\n    real    0m1.550s\n    user    0m1.512s\n    sys     0m0.060s\n\n  On Windows, before:\n\n    real    0m3.128s\n    user    0m2.155s\n    sys     0m0.183s\n\n  After:\n\n    real    0m2.781s\n    user    0m1.826s\n    sys     0m0.136s\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex e2c4794f3..9f5a6f44e 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -414,8 +414,9 @@ __git_refs ()\n \t\t\t# Try to find a remote branch that matches the completion word\n \t\t\t# but only output if the branch name is unique\n \t\t\t__git for-each-ref --format=\"%(refname:strip=3)\" \\\n+\t\t\t\t--sort=\"refname:strip=3\" \\\n \t\t\t\t\"refs/remotes/*/$cur_*\" \"refs/remotes/*/$cur_*/**\" | \\\n-\t\t\tsort | uniq -u\n+\t\t\tuniq -u\n \t\tfi\n \t\treturn\n \tfi\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310778","messageId":"20170203025405.8242-12-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 11/12] completion: list only matching symbolic and pseudorefs when completing refs","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:54:04Z","receivedAt":"2017-02-03T02:54:53Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"The previous changes in this series ensure that __git_refs() lists\nonly refs that match the current word to be completed, but\nnon-matching symbolic and pseudo refs still show up in its output.\n\nFilter out non-matching symbolic and pseudo refs as well, so anything\n__git_refs() outputs matches the current word to be completed, as it\nwill allow us to optimize how refs are placed into the COMPREPLY\narray.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 20 ++++++++++++++++----\n t/t9902-completion.sh                  |  4 ----\n 2 files changed, 16 insertions(+), 8 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 9f5a6f44e..0ad02cec6 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -355,7 +355,8 @@ __git_tags ()\n # 2: In addition to local refs, list unique branches from refs/remotes/ for\n #    'git checkout's tracking DWIMery (optional; ignored, if set but empty).\n # 3: Currently ignored.\n-# 4: The current ref to be completed (optional).\n+# 4: List only refs matching this word instead of the current word being\n+#    completed (optional).\n #\n # Use __git_complete_refs() instead.\n __git_refs ()\n@@ -399,7 +400,12 @@ __git_refs ()\n \t\t\t;;\n \t\t*)\n \t\t\tfor i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do\n-\t\t\t\tif [ -e \"$dir/$i\" ]; then echo $pfx$i; fi\n+\t\t\t\tcase \"$i\" in\n+\t\t\t\t$cur_*)\tif [ -e \"$dir/$i\" ]; then\n+\t\t\t\t\t\techo $pfx$i\n+\t\t\t\t\tfi\n+\t\t\t\t\t;;\n+\t\t\t\tesac\n \t\t\tdone\n \t\t\tformat=\"refname:strip=2\"\n \t\t\trefs=(\"refs/tags/$cur_*\" \"refs/tags/$cur_*/**\"\n@@ -432,12 +438,18 @@ __git_refs ()\n \t\t;;\n \t*)\n \t\tif [ \"$list_refs_from\" = remote ]; then\n-\t\t\techo \"HEAD\"\n+\t\t\tcase \"HEAD\" in\n+\t\t\t$cur_*)\techo \"HEAD\" ;;\n+\t\t\tesac\n \t\t\t__git for-each-ref --format=\"%(refname:strip=3)\" \\\n \t\t\t\t\"refs/remotes/$remote/$cur_*\" \\\n \t\t\t\t\"refs/remotes/$remote/$cur_*/**\"\n \t\telse\n-\t\t\t__git ls-remote \"$remote\" HEAD \\\n+\t\t\tlocal query_symref\n+\t\t\tcase \"HEAD\" in\n+\t\t\t$cur_*)\tquery_symref=\"HEAD\" ;;\n+\t\t\tesac\n+\t\t\t__git ls-remote \"$remote\" $query_symref \\\n \t\t\t\t\"refs/tags/$cur_*\" \"refs/heads/$cur_*\" \\\n \t\t\t\t\"refs/remotes/$cur_*\" |\n \t\t\twhile read -r hash i; do\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 499be5879..5e06acc17 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -847,7 +847,6 @@ test_expect_success 'setup for filtering matching refs' '\n \n test_expect_success '__git_refs - only matching refs' '\n \tcat >expected <<-EOF &&\n-\tHEAD\n \tmatching-branch\n \tmatching/branch\n \tmatching-tag\n@@ -874,7 +873,6 @@ test_expect_success '__git_refs - only matching refs - full refs' '\n \n test_expect_success '__git_refs - only matching refs - remote on local file system' '\n \tcat >expected <<-EOF &&\n-\tHEAD\n \tmaster-in-other\n \tmatching/branch-in-other\n \tEOF\n@@ -887,7 +885,6 @@ test_expect_success '__git_refs - only matching refs - remote on local file syst\n \n test_expect_success '__git_refs - only matching refs - configured remote' '\n \tcat >expected <<-EOF &&\n-\tHEAD\n \tmaster-in-other\n \tmatching/branch-in-other\n \tEOF\n@@ -912,7 +909,6 @@ test_expect_success '__git_refs - only matching refs - remote - full refs' '\n \n test_expect_success '__git_refs - only matching refs - checkout DWIMery' '\n \tcat >expected <<-EOF &&\n-\tHEAD\n \tmatching-branch\n \tmatching/branch\n \tmatching-tag\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310779","messageId":"20170203025405.8242-7-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 06/12] completion: don't disambiguate short refs","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:53:59Z","receivedAt":"2017-02-03T02:54:56Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"When the completion script lists short refs it does so using the 'git\nfor-each-ref' format 'refname:short', which makes sure that all listed\nrefs are unambiguous.  While disambiguating refs is technically\ncorrect in this case, as opposed to the cases discussed in the\nprevious patch, this disambiguation involves several stat() syscalls\nfor each ref, thus, unfortunately, comes at a steep cost especially on\nWindows and/or when there are a lot of refs to be listed.  A user of\nGit for Windows reported[1] 'git checkout <TAB>' taking ~11 seconds in\na repository with just about 4000 refs.\n\nHowever, it's questionable whether ambiguous refs are really that bad\nto justify that much extra cost:\n\n  - Ambiguous refs are not that common,\n  - even if a repository contains ambiguous refs, they only hurt when\n    the user actually happens to want to do something with one of the\n    ambiguous refs, and\n  - the issue can be easily circumvented by renaming those ambiguous\n    refs.\n\n  - On the other hand, apparently not that many refs are needed to\n    make refs completion unacceptably slow on Windows,\n  - and this slowness bites each and every time the user attempts refs\n    completion, even when the repository doesn't contain any ambiguous\n    refs.\n  - Furthermore, circumventing the issue might not be possible or\n    might be considerably more difficult and requires various\n    trade-offs (e.g. working in a repository with only a few selected\n    important refs while keeping a separate repository with all refs\n    for reference).\n\nArguably, in this case the benefits of technical correctness are\nrather minor compared to the price we pay for it, and we are better\noff opting for performance over correctness.\n\nUse the 'git for-each-ref' format 'refname:strip=2' to list short refs\nto spare the substantial cost of disambiguating.\n\nThis speeds up refs completion considerably.  Uniquely completing a\nbranch in a repository with 100k local branches, all packed, best of\nfive:\n\n  On Linux, before:\n\n    $ time __git_complete_refs --cur=maste\n\n    real    0m1.662s\n    user    0m1.368s\n    sys     0m0.296s\n\n  After:\n\n    real    0m0.831s\n    user    0m0.808s\n    sys     0m0.028s\n\n  On Windows, before:\n\n    real    0m12.457s\n    user    0m1.016s\n    sys     0m0.092s\n\n  After:\n\n    real    0m1.480s\n    user    0m1.031s\n    sys     0m0.060s\n\n[1] - https://github.com/git-for-windows/git/issues/524\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 19799e3ba..d55eadfd1 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -401,7 +401,7 @@ __git_refs ()\n \t\t\tfor i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do\n \t\t\t\tif [ -e \"$dir/$i\" ]; then echo $pfx$i; fi\n \t\t\tdone\n-\t\t\tformat=\"refname:short\"\n+\t\t\tformat=\"refname:strip=2\"\n \t\t\trefs=\"refs/tags refs/heads refs/remotes\"\n \t\t\t;;\n \t\tesac\n@@ -412,7 +412,7 @@ __git_refs ()\n \t\t\t# Try to find a remote branch that matches the completion word\n \t\t\t# but only output if the branch name is unique\n \t\t\tlocal ref entry\n-\t\t\t__git for-each-ref --shell --format=\"ref=%(refname:short)\" \\\n+\t\t\t__git for-each-ref --shell --format=\"ref=%(refname:strip=2)\" \\\n \t\t\t\t\"refs/remotes/\" | \\\n \t\t\twhile read -r entry; do\n \t\t\t\teval \"$entry\"\n@@ -437,7 +437,7 @@ __git_refs ()\n \t*)\n \t\tif [ \"$list_refs_from\" = remote ]; then\n \t\t\techo \"HEAD\"\n-\t\t\t__git for-each-ref --format=\"%(refname:short)\" \\\n+\t\t\t__git for-each-ref --format=\"%(refname:strip=2)\" \\\n \t\t\t\t\"refs/remotes/$remote/\" | sed -e \"s#^$remote/##\"\n \t\telse\n \t\t\t__git ls-remote \"$remote\" HEAD \\\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310780","messageId":"20170203025405.8242-5-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 04/12] completion: support excluding full refs","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:53:57Z","receivedAt":"2017-02-03T02:54:59Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Commit 49416ad22 (completion: support excluding refs, 2016-08-24) made\npossible to complete short refs with a '^' prefix.\n\nExtend the support to full refs to make completing '^refs/...' work.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash |  8 ++++----\n t/t9902-completion.sh                  | 31 +++++++++++++++++++++++++++++++\n 2 files changed, 35 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 67a03cfd4..63e803154 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -387,6 +387,10 @@ __git_refs ()\n \tfi\n \n \tif [ \"$list_refs_from\" = path ]; then\n+\t\tif [[ \"$cur_\" == ^* ]]; then\n+\t\t\tpfx=\"^\"\n+\t\t\tcur_=${cur_#^}\n+\t\tfi\n \t\tcase \"$cur_\" in\n \t\trefs|refs/*)\n \t\t\tformat=\"refname\"\n@@ -394,10 +398,6 @@ __git_refs ()\n \t\t\ttrack=\"\"\n \t\t\t;;\n \t\t*)\n-\t\t\tif [[ \"$cur_\" == ^* ]]; then\n-\t\t\t\tpfx=\"^\"\n-\t\t\t\tcur_=${cur_#^}\n-\t\t\tfi\n \t\t\tfor i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do\n \t\t\t\tif [ -e \"$dir/$i\" ]; then echo $pfx$i; fi\n \t\t\tdone\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 8fe748839..7b42a686c 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -806,6 +806,37 @@ test_expect_success '__git_refs - after --opt= - full refs' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success '__git refs - exluding refs' '\n+\tcat >expected <<-EOF &&\n+\t^HEAD\n+\t^master\n+\t^matching-branch\n+\t^other/branch-in-other\n+\t^other/master-in-other\n+\t^matching-tag\n+\tEOF\n+\t(\n+\t\tcur=^ &&\n+\t\t__git_refs >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success '__git refs - exluding full refs' '\n+\tcat >expected <<-EOF &&\n+\t^refs/heads/master\n+\t^refs/heads/matching-branch\n+\t^refs/remotes/other/branch-in-other\n+\t^refs/remotes/other/master-in-other\n+\t^refs/tags/matching-tag\n+\tEOF\n+\t(\n+\t\tcur=^refs/ &&\n+\t\t__git_refs >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_expect_success '__git_complete_refs - simple' '\n \tsed -e \"s/Z$//g\" >expected <<-EOF &&\n \tHEAD Z\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310781","messageId":"20170203025405.8242-6-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 05/12] completion: don't disambiguate tags and branches","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:53:58Z","receivedAt":"2017-02-03T02:55:00Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"When the completion script has to list only tags or only branches, it\nuses the 'git for-each-ref' format 'refname:short', which makes sure\nthat all listed tags and branches are unambiguous.  However,\ndisambiguating tags and branches in these cases is wrong, because:\n\n  - __git_tags(), the helper function listing possible tagname\n    arguments for 'git tag', lists an ambiguous tag\n    'refs/tags/ambiguous' as 'tags/ambiguous'.  Its only consumer,\n    'git tag' expects its tagname argument to be under 'refs/tags/',\n    thus it interprets that abgiguous tag as\n    'refs/tags/tags/ambiguous'.  Clearly wrong.\n\n  - __git_heads() lists possible branchname arguments for 'git branch'\n    and possible 'branch.<branchname>' configuration subsections.\n    Both of these expect branchnames to be under 'refs/heads/' and\n    misinterpret a disambiguated branchname like 'heads/ambiguous'.\n\nFurthermore, disambiguation involves several stat() syscalls for each\ntag or branch, thus comes at a steep cost especially on Windows and/or\nwhen there are a lot of tags or branches to be listed.\n\nUse the 'git for-each-ref' format 'refname:strip=2' instead of\n'refname:short' to avoid harmful disambiguation of tags and branches\nin __git_tags() and __git_heads().\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 63e803154..19799e3ba 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -340,12 +340,12 @@ __git_index_files ()\n \n __git_heads ()\n {\n-\t__git for-each-ref --format='%(refname:short)' refs/heads\n+\t__git for-each-ref --format='%(refname:strip=2)' refs/heads\n }\n \n __git_tags ()\n {\n-\t__git for-each-ref --format='%(refname:short)' refs/tags\n+\t__git for-each-ref --format='%(refname:strip=2)' refs/tags\n }\n \n # Lists refs from the local (by default) or from a remote repository.\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310782","messageId":"20170203025405.8242-10-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"[PATCH 09/12] completion: let 'for-each-ref' filter remote branches for 'checkout' DWIMery","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-03T02:54:02Z","receivedAt":"2017-02-03T02:55:03Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"The code listing unique remote branches for 'git checkout's tracking\nDWIMery outputs only remote branches that match the current word to be\ncompleted, but the filtering is done in a shell loop iterating over\nall remote refs.\n\nLet 'git for-each-ref' do the filtering, as it can do so much more\nefficiently and we can remove that shell loop entirely.\n\nThis speeds up refs completion for 'git checkout' considerably when\nthere are a lot of non-matching remote refs to be filtered out.\nUniquely completing a branch in a repository with 100k remote\nbranches, all packed, best of five:\n\n  On Linux, before:\n\n    $ time __git_complete_refs --cur=maste --track\n\n    real    0m1.993s\n    user    0m1.740s\n    sys     0m0.304s\n\n  After:\n\n    real    0m0.266s\n    user    0m0.248s\n    sys     0m0.012s\n\n  On Windows, before:\n\n    real    0m6.187s\n    user    0m3.358s\n    sys     0m2.121s\n\n  After:\n\n    real    0m0.750s\n    user    0m0.015s\n    sys     0m0.090s\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n contrib/completion/git-completion.bash | 12 +++---------\n 1 file changed, 3 insertions(+), 9 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8f1203025..e2c4794f3 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -413,15 +413,9 @@ __git_refs ()\n \t\t\t# employ the heuristic used by git checkout\n \t\t\t# Try to find a remote branch that matches the completion word\n \t\t\t# but only output if the branch name is unique\n-\t\t\tlocal ref entry\n-\t\t\t__git for-each-ref --shell --format=\"ref=%(refname:strip=3)\" \\\n-\t\t\t\t\"refs/remotes/\" | \\\n-\t\t\twhile read -r entry; do\n-\t\t\t\teval \"$entry\"\n-\t\t\t\tif [[ \"$ref\" == \"$cur_\"* ]]; then\n-\t\t\t\t\techo \"$ref\"\n-\t\t\t\tfi\n-\t\t\tdone | sort | uniq -u\n+\t\t\t__git for-each-ref --format=\"%(refname:strip=3)\" \\\n+\t\t\t\t\"refs/remotes/*/$cur_*\" \"refs/remotes/*/$cur_*/**\" | \\\n+\t\t\tsort | uniq -u\n \t\tfi\n \t\treturn\n \tfi\n-- \n2.11.0.555.g967c1bcb3\n\n"},{"id":"310784","messageId":"CA+P7+xqhjVQMXtO4gtQ_2VAVd3qrpVLncH6YpFHreVV2mHORxg@mail.gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-1-szeder.dev@gmail.com","subject":"Re: [PATCH 00/12] completion: speed up refs completion","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-02-03T04:15:36Z","receivedAt":"2017-02-03T04:16:03Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Thu, Feb 2, 2017 at 6:53 PM, SZEDER Gábor <szeder.dev@gmail.com> wrote:\n> This series speeds up refs completion for large number of refs, partly\n> by giving up disambiguating ambiguous refs (patch 6) and partly by\n> eliminating most of the shell processing between 'git for-each-ref'\n> and 'ls-remote' and Bash's completion facility.  The rest is a bit of\n> preparatory reorganization, cleanup and bugfixes.\n>\n> The last patch touches the ZSH wrapper, too.  By a lucky educated\n> guess I managed to get it work on the first try, but I don't really\n> know what I've actually done, so...  ZSH users, please have a closer\n> look.\n>\n> At the end of this series refs completion from a local repository is\n> as fast as it can possibly get, at least as far as the completion\n> script is concerned, because it basically does nothing anymore :)  All\n> it does is run 'git for-each-ref' with assorted options to do all the\n> work, and feed its output directly, without any processing into Bash's\n> COMPREPLY array.  There is still room for improvements in the code\n> paths using 'git ls-remote', but for that we would need enhancements\n> to 'ls-remote'.\n>\n> It goes on top of the __gitdir() improvements series I just posted at:\n>\n>   http://public-inbox.org/git/20170203024829.8071-1-szeder.dev@gmail.com/T/\n>\n> This series is also available at:\n>\n>   https://github.com/szeder/git completion-refs-speedup\n>\n\nNice! This is something i've been bothered by in the past since\ncompletion would take a rather long time!\n\nRegards,\nJake\n"},{"id":"310830","messageId":"CA+P7+xpeyebN3pmSX09Avh1EvYVjALpBCQ9r2==q3SWTu3GMSw@mail.gmail.com","threadId":"45031","inReplyTo":"CA+P7+xqhjVQMXtO4gtQ_2VAVd3qrpVLncH6YpFHreVV2mHORxg@mail.gmail.com","subject":"Re: [PATCH 00/12] completion: speed up refs completion","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-02-04T03:15:38Z","receivedAt":"2017-02-04T03:16:05Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Thu, Feb 2, 2017 at 8:15 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n> On Thu, Feb 2, 2017 at 6:53 PM, SZEDER Gábor <szeder.dev@gmail.com> wrote:\n>> This series speeds up refs completion for large number of refs, partly\n>> by giving up disambiguating ambiguous refs (patch 6) and partly by\n>> eliminating most of the shell processing between 'git for-each-ref'\n>> and 'ls-remote' and Bash's completion facility.  The rest is a bit of\n>> preparatory reorganization, cleanup and bugfixes.\n>>\n>> The last patch touches the ZSH wrapper, too.  By a lucky educated\n>> guess I managed to get it work on the first try, but I don't really\n>> know what I've actually done, so...  ZSH users, please have a closer\n>> look.\n>>\n>> At the end of this series refs completion from a local repository is\n>> as fast as it can possibly get, at least as far as the completion\n>> script is concerned, because it basically does nothing anymore :)  All\n>> it does is run 'git for-each-ref' with assorted options to do all the\n>> work, and feed its output directly, without any processing into Bash's\n>> COMPREPLY array.  There is still room for improvements in the code\n>> paths using 'git ls-remote', but for that we would need enhancements\n>> to 'ls-remote'.\n>>\n>> It goes on top of the __gitdir() improvements series I just posted at:\n>>\n>>   http://public-inbox.org/git/20170203024829.8071-1-szeder.dev@gmail.com/T/\n>>\n>> This series is also available at:\n>>\n>>   https://github.com/szeder/git completion-refs-speedup\n>>\n>\n> Nice! This is something i've been bothered by in the past since\n> completion would take a rather long time!\n>\n> Regards,\n> Jake\n\nI haven't had a chance to further investigate, but I tried this series\nout (from your github) and it appears that this series (or the\nprevious series for __gitdir work) breaks \"git log\" ref completion.\nI'll have further details when I am able to investigate a it more.\n\nThanks,\nJake\n"},{"id":"310835","messageId":"xmqq8tpm8oho.fsf@gitster.mtv.corp.google.com","threadId":"45031","inReplyTo":"CA+P7+xpeyebN3pmSX09Avh1EvYVjALpBCQ9r2==q3SWTu3GMSw@mail.gmail.com","subject":"Re: [PATCH 00/12] completion: speed up refs completion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-04T06:21:55Z","receivedAt":"2017-02-04T06:22:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n> On Thu, Feb 2, 2017 at 8:15 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n>> On Thu, Feb 2, 2017 at 6:53 PM, SZEDER Gábor <szeder.dev@gmail.com> wrote:\n>>> This series speeds up refs completion for large number of refs, partly\n>>> by giving up disambiguating ambiguous refs (patch 6) and partly by\n>>> ...\n>>> It goes on top of the __gitdir() improvements series I just posted at:\n>>>\n>>>   http://public-inbox.org/git/20170203024829.8071-1-szeder.dev@gmail.com/T/\n>>>\n>> Nice! This is something i've been bothered by in the past since\n>> completion would take a rather long time!\n>\n> I haven't had a chance to further investigate, but I tried this series\n> out (from your github) and it appears that this series (or the\n> previous series for __gitdir work) breaks \"git log\" ref completion.\n> I'll have further details when I am able to investigate a it more.\n\nThanks, both.  I'll look forward to how the story unfolds from\nsidelines ;-)\n\n"},{"id":"310929","messageId":"20170206181545.12869-1-szeder.dev@gmail.com","threadId":"45031","inReplyTo":"20170203025405.8242-13-szeder.dev@gmail.com","subject":"[PATCH] squash! completion: fill COMPREPLY directly when completing refs","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-06T18:15:45Z","receivedAt":"2017-02-06T18:26:00Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Care should be taken, though, because that prefix might contain\n'for-each-ref' format specifiers as part of the left hand side of a\n'..' range or '...' symmetric difference notation or fetch/push/etc.\nrefspec, e.g. 'git log \"evil-%(refname)..br<TAB>'.  Doubling every '%'\nin the prefix will prevent 'git for-each-ref' from interpolating any\nof those contained format specifiers.\n---\n\nThis is really pathological, and I'm sure this has nothing to do with\nwhatever breakage Jacob experienced.\nThe shell metacharacters '(' and ')' still cause us trouble in various\nways, but that's nothing new and has been the case for quite a while\n(always?).\n\nIt's already incorporated into (the rewritten)\n\n  https://github.com/szeder/git completion-refs-speedup\n\n contrib/completion/git-completion.bash |  8 +++++---\n t/t9902-completion.sh                  | 11 +++++++++++\n 2 files changed, 16 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex dbbb62f5f..058f1d0ee 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -381,6 +381,7 @@ __git_refs ()\n \tlocal list_refs_from=path remote=\"${1-}\"\n \tlocal format refs\n \tlocal pfx=\"${3-}\" cur_=\"${4-$cur}\" sfx=\"${5-}\"\n+\tlocal fer_pfx=\"${pfx//\\%/%%}\"\n \n \t__git_find_repo_path\n \tdir=\"$__git_repo_path\"\n@@ -406,6 +407,7 @@ __git_refs ()\n \tif [ \"$list_refs_from\" = path ]; then\n \t\tif [[ \"$cur_\" == ^* ]]; then\n \t\t\tpfx=\"$pfx^\"\n+\t\t\tfer_pfx=\"$fer_pfx^\"\n \t\t\tcur_=${cur_#^}\n \t\tfi\n \t\tcase \"$cur_\" in\n@@ -429,13 +431,13 @@ __git_refs ()\n \t\t\t\t\"refs/remotes/$cur_*\" \"refs/remotes/$cur_*/**\")\n \t\t\t;;\n \t\tesac\n-\t\t__git_dir=\"$dir\" __git for-each-ref --format=\"$pfx%($format)$sfx\" \\\n+\t\t__git_dir=\"$dir\" __git for-each-ref --format=\"$fer_pfx%($format)$sfx\" \\\n \t\t\t\"${refs[@]}\"\n \t\tif [ -n \"$track\" ]; then\n \t\t\t# employ the heuristic used by git checkout\n \t\t\t# Try to find a remote branch that matches the completion word\n \t\t\t# but only output if the branch name is unique\n-\t\t\t__git for-each-ref --format=\"$pfx%(refname:strip=3)$sfx\" \\\n+\t\t\t__git for-each-ref --format=\"$fer_pfx%(refname:strip=3)$sfx\" \\\n \t\t\t\t--sort=\"refname:strip=3\" \\\n \t\t\t\t\"refs/remotes/*/$cur_*\" \"refs/remotes/*/$cur_*/**\" | \\\n \t\t\tuniq -u\n@@ -457,7 +459,7 @@ __git_refs ()\n \t\t\tcase \"HEAD\" in\n \t\t\t$cur_*)\techo \"${pfx}HEAD$sfx\" ;;\n \t\t\tesac\n-\t\t\t__git for-each-ref --format=\"$pfx%(refname:strip=3)$sfx\" \\\n+\t\t\t__git for-each-ref --format=\"$fer_pfx%(refname:strip=3)$sfx\" \\\n \t\t\t\t\"refs/remotes/$remote/$cur_*\" \\\n \t\t\t\t\"refs/remotes/$remote/$cur_*/**\"\n \t\telse\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 1206a38ed..be584c069 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -951,6 +951,17 @@ test_expect_success 'teardown after filtering matching refs' '\n \tgit update-ref -d refs/remotes/other/matching/branch-in-other\n '\n \n+test_expect_success '__git_refs - for-each-ref format specifiers in prefix' '\n+\tcat >expected <<-EOF &&\n+\tevil-%%-%42-%(refname)..master\n+\tEOF\n+\t(\n+\t\tcur=\"evil-%%-%42-%(refname)..mas\" &&\n+\t\t__git_refs \"\" \"\" \"evil-%%-%42-%(refname)..\" mas >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_expect_success '__git_complete_refs - simple' '\n \tsed -e \"s/Z$//g\" >expected <<-EOF &&\n \tHEAD Z\n-- \n2.11.1.499.gb6fcc8b3a\n\n"},{"id":"310931","messageId":"CA+P7+xrAVM8C1dnEaY1VnTUwiCzoMzh+rbMqBknyBG27grs-uQ@mail.gmail.com","threadId":"45031","inReplyTo":"CA+P7+xpeyebN3pmSX09Avh1EvYVjALpBCQ9r2==q3SWTu3GMSw@mail.gmail.com","subject":"Re: [PATCH 00/12] completion: speed up refs completion","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-02-06T18:31:24Z","receivedAt":"2017-02-06T18:31:51Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Fri, Feb 3, 2017 at 7:15 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n> I haven't had a chance to further investigate, but I tried this series\n> out (from your github) and it appears that this series (or the\n> previous series for __gitdir work) breaks \"git log\" ref completion.\n> I'll have further details when I am able to investigate a it more.\n>\n> Thanks,\n> Jake\n\nAt first I had the same problem, but I verified by re-installing the\ncompletion script and the problem appears to have gone away. I suspect\nwhat happened is that the original time, I forgot to actually install\nthe new version of git, and only installed the completion script, so\nwhen some of the commands were run with new options they (silently)\nfailed and the result was missing completion values.\n\nOnce I properly re-installed everything it appears to work as\nexpected. I haven't found any other issues yet.\n\nRegards,\nJake\n"},{"id":"310938","messageId":"CAM0VKjm-HQFtDypcWgOdQrLyjAicOVLUsFby5_wE1hvTE1pTRQ@mail.gmail.com","threadId":"45031","inReplyTo":"CA+P7+xrAVM8C1dnEaY1VnTUwiCzoMzh+rbMqBknyBG27grs-uQ@mail.gmail.com","subject":"Re: [PATCH 00/12] completion: speed up refs completion","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-06T19:36:00Z","receivedAt":"2017-02-06T19:36:07Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, Feb 6, 2017 at 7:31 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n> On Fri, Feb 3, 2017 at 7:15 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n>> I haven't had a chance to further investigate, but I tried this series\n>> out (from your github) and it appears that this series (or the\n>> previous series for __gitdir work) breaks \"git log\" ref completion.\n>> I'll have further details when I am able to investigate a it more.\n>>\n>> Thanks,\n>> Jake\n>\n> At first I had the same problem, but I verified by re-installing the\n> completion script and the problem appears to have gone away. I suspect\n> what happened is that the original time, I forgot to actually install\n> the new version of git, and only installed the completion script, so\n> when some of the commands were run with new options they (silently)\n> failed and the result was missing completion values.\n>\n> Once I properly re-installed everything it appears to work as\n> expected. I haven't found any other issues yet.\n\nThanks, that's good to hear.\n\nStill, I'm a bit puzzled as to what exactly might have caused your\nproblem.  Considering new options:\n\n  - the __gitdir()-related series added the 'git rev-parse\n    --absolute-git-dir' option, but only ever used it if you invoked\n    completion after 'git -C some/where'.\n\n - The refs completion speedup didn't add any new options but started\n   to use two that it previously didn't:\n\n   - 'git for-each-ref --sort=<key>' option, but that's with us since\n     the earliest ever 'for-each-ref' version from more than a decade\n     ago...\n\n   - 'git for-each-ref' format modifier 'strip=2', which was\n     introduced in v2.7.1~15^2 (tag: do not show ambiguous tag names\n     as \"tags/foo\", 2016-01-25), only about a year ago.  Were you\n     using a pre-2.7.1 version when seeing the problems?\n\nGábor\n"},{"id":"310955","messageId":"CA+P7+xo7Kz0Zi_vK7qLEicFyrSms2aMXJCrdiEQ=sAHHsh3z7Q@mail.gmail.com","threadId":"45031","inReplyTo":"CAM0VKjm-HQFtDypcWgOdQrLyjAicOVLUsFby5_wE1hvTE1pTRQ@mail.gmail.com","subject":"Re: [PATCH 00/12] completion: speed up refs completion","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-02-06T23:55:12Z","receivedAt":"2017-02-06T23:55:41Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Mon, Feb 6, 2017 at 11:36 AM, SZEDER Gábor <szeder.dev@gmail.com> wrote:\n> On Mon, Feb 6, 2017 at 7:31 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n>> On Fri, Feb 3, 2017 at 7:15 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n>>> I haven't had a chance to further investigate, but I tried this series\n>>> out (from your github) and it appears that this series (or the\n>>> previous series for __gitdir work) breaks \"git log\" ref completion.\n>>> I'll have further details when I am able to investigate a it more.\n>>>\n>>> Thanks,\n>>> Jake\n>>\n>> At first I had the same problem, but I verified by re-installing the\n>> completion script and the problem appears to have gone away. I suspect\n>> what happened is that the original time, I forgot to actually install\n>> the new version of git, and only installed the completion script, so\n>> when some of the commands were run with new options they (silently)\n>> failed and the result was missing completion values.\n>>\n>> Once I properly re-installed everything it appears to work as\n>> expected. I haven't found any other issues yet.\n>\n> Thanks, that's good to hear.\n>\n> Still, I'm a bit puzzled as to what exactly might have caused your\n> problem.  Considering new options:\n>\n>   - the __gitdir()-related series added the 'git rev-parse\n>     --absolute-git-dir' option, but only ever used it if you invoked\n>     completion after 'git -C some/where'.\n>\n>  - The refs completion speedup didn't add any new options but started\n>    to use two that it previously didn't:\n>\n>    - 'git for-each-ref --sort=<key>' option, but that's with us since\n>      the earliest ever 'for-each-ref' version from more than a decade\n>      ago...\n>\n>    - 'git for-each-ref' format modifier 'strip=2', which was\n>      introduced in v2.7.1~15^2 (tag: do not show ambiguous tag names\n>      as \"tags/foo\", 2016-01-25), only about a year ago.  Were you\n>      using a pre-2.7.1 version when seeing the problems?\n>\n> Gábor\n\nNope. I was using some version of next at some point recently (less\nthan a couple months old). I do not know exactly what caused it, and\nI'm not really able to find out because I can't reproduce it any more.\n(after a fresh make install).\n\nThanks,\nJake\n"},{"id":"311318","messageId":"xmqq7f4xk9es.fsf@gitster.mtv.corp.google.com","threadId":"45031","inReplyTo":"20170206181545.12869-1-szeder.dev@gmail.com","subject":"Re: [PATCH] squash! completion: fill COMPREPLY directly when completing refs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-10T21:44:59Z","receivedAt":"2017-02-10T21:45:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n> Care should be taken, though, because that prefix might contain\n> 'for-each-ref' format specifiers as part of the left hand side of a\n> '..' range or '...' symmetric difference notation or fetch/push/etc.\n> refspec, e.g. 'git log \"evil-%(refname)..br<TAB>'.  Doubling every '%'\n> in the prefix will prevent 'git for-each-ref' from interpolating any\n> of those contained format specifiers.\n> ---\n>\n> This is really pathological, and I'm sure this has nothing to do\n> with whatever breakage Jacob experienced.  The shell\n> metacharacters '(' and ')' still cause us trouble in various ways,\n> but that's nothing new and has been the case for quite a while\n> (always?).\n>\n> It's already incorporated into (the rewritten)\n>\n>   https://github.com/szeder/git completion-refs-speedup\n\nShould I expect a reroll to come, or is this the only fix-up to the\nseries that begins at <20170203025405.8242-1-szeder.dev@gmail.com>?\n\nNo hurries.\n"},{"id":"311422","messageId":"CAM0VKj=Pai0fL7KtMdv1sg3N2KA1aBafGQ_XzXWKUsBmo62ZoA@mail.gmail.com","threadId":"45031","inReplyTo":"xmqq7f4xk9es.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] squash! completion: fill COMPREPLY directly when completing refs","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2017-02-13T19:32:52Z","receivedAt":"2017-02-13T19:32:58Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Feb 10, 2017 at 10:44 PM, Junio C Hamano <gitster@pobox.com> wrote:\n\n> Should I expect a reroll to come, or is this the only fix-up to the\n> series that begins at <20170203025405.8242-1-szeder.dev@gmail.com>?\n>\n> No hurries.\n\nYes, definitely.\n\nI found a minor bug in the middle of the series, and haven't quite\nmade up my mind about it and its fix yet.  Perhaps in a day or three.\n\nRegarding the 'strip' -> 'lstrip' 'for-each-ref' format modifier\nrename that broke pu: I should keep using 'strip', right?\n\nGábor\n"},{"id":"311430","messageId":"xmqqshnhdeka.fsf@gitster.mtv.corp.google.com","threadId":"45031","inReplyTo":"CAM0VKj=Pai0fL7KtMdv1sg3N2KA1aBafGQ_XzXWKUsBmo62ZoA@mail.gmail.com","subject":"Re: [PATCH] squash! completion: fill COMPREPLY directly when completing refs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-13T20:24:37Z","receivedAt":"2017-02-13T20:24:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n> On Fri, Feb 10, 2017 at 10:44 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>\n>> Should I expect a reroll to come, or is this the only fix-up to the\n>> series that begins at <20170203025405.8242-1-szeder.dev@gmail.com>?\n>>\n>> No hurries.\n>\n> Yes, definitely.\n>\n> I found a minor bug in the middle of the series, and haven't quite\n> made up my mind about it and its fix yet.  Perhaps in a day or three.\n>\n> Regarding the 'strip' -> 'lstrip' 'for-each-ref' format modifier\n> rename that broke pu: I should keep using 'strip', right?\n\nRight.  I view the removal of 'strip' as an accident when 'lstrip'\nwas introduced, not an intended change.\n"}]}