{"thread":{"id":"35585","subject":"[PATCH 1/4] completion: prioritize ./git-completion.bash","startedAt":"2013-12-30T14:52:14Z","lastAt":"2014-01-03T19:13:28Z","messageCount":14,"participants":["Ramkumar Ramachandra","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"232507","messageId":"1388415138-11011-1-git-send-email-artagnon@gmail.com","threadId":"35585","inReplyTo":null,"subject":"[PATCH 0/4] Fix branch.autosetup(merge|rebase) completion","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-12-30T14:52:14Z","receivedAt":"2013-12-30T14:52:14Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nI figured that branch.autosetupmerge, branch.autosetuprebase and\nremote.pushdefault are very tedious to type out in full, and started\nlooking into fixing their completions this evening. The solution turns\nout to be much more complex than I initally imagined, but I'm quite\nhappy with the solution.\n\nI hope it's an enjoyable read.\n\nRamkumar Ramachandra (4):\n  completion: prioritize ./git-completion.bash\n  completion: introduce __gitcomp_2 ()\n  completion: fix branch.autosetup(merge|rebase)\n  completion: fix remote.pushdefault\n\n contrib/completion/git-completion.bash | 43 ++++++++++++++++++++++++++++++++--\n contrib/completion/git-completion.zsh  | 12 +++++++++-\n 2 files changed, 52 insertions(+), 3 deletions(-)\n\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232506","messageId":"1388415138-11011-2-git-send-email-artagnon@gmail.com","threadId":"35585","inReplyTo":"1388415138-11011-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 1/4] completion: prioritize ./git-completion.bash","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-12-30T14:52:15Z","receivedAt":"2013-12-30T14:52:15Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"To ease development, prioritize ./git-completion.bash over other\nstandard system paths.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-completion.zsh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex fac5e71..6fca145 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -30,10 +30,10 @@ if [ -z \"$script\" ]; then\n \tlocal -a locations\n \tlocal e\n \tlocations=(\n+\t\t$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash\n \t\t'/etc/bash_completion.d/git' # fedora, old debian\n \t\t'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian\n \t\t'/usr/share/bash-completion/git' # gentoo\n-\t\t$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash\n \t\t)\n \tfor e in $locations; do\n \t\ttest -f $e && script=\"$e\" && break\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232510","messageId":"1388415138-11011-3-git-send-email-artagnon@gmail.com","threadId":"35585","inReplyTo":"1388415138-11011-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 2/4] completion: introduce __gitcomp_2 ()","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-12-30T14:52:16Z","receivedAt":"2013-12-30T14:52:16Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"There are situations where two classes of completions possible. For\nexample\n\n  branch.<TAB>\n\nshould try to complete\n\n  branch.master.\n  branch.autosetupmerge\n  branch.autosetuprebase\n\nThe first candidate has the suffix \".\", and the second/ third candidates\nhave the suffix \" \". To facilitate completions of this kind, create a\nvariation of __gitcomp_nl () that accepts two sets of arguments and two\nindependent suffixes.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-completion.bash | 30 ++++++++++++++++++++++++++++++\n contrib/completion/git-completion.zsh  | 10 ++++++++++\n 2 files changed, 40 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 51c2dd4..64b20b8 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -233,6 +233,36 @@ __gitcomp_nl ()\n \t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n }\n \n+# Generates completion reply from two sets of completion words, with\n+# configurable suffixes for each.\n+#\n+# It accepts 2 to 6 arguments:\n+# 1: First set of possible completion words.\n+# 2: Second set of possible completion words.\n+# 3: A prefix to be added to each completion word (both $1 and $2)\n+#    (optional).\n+# 4: Generate possible completion matches for this word (optional).\n+# 5: A suffix to be appended to each completion word in the first set\n+#    ($1) instead of the default space (optional).\n+# 6: A suffix to be appended to each completion word in the second set\n+#    ($2) instead of the default space (optional).\n+__gitcomp_2 ()\n+{\n+\tlocal pfx=\"${3-}\" cur_=\"${4-$cur}\" sfx=\"${5- }\" sfx2=\"${6- }\" i=0\n+\tlocal IFS=$' \\t\\n'\n+\n+\tfor x in $1; do\n+\t\tif [[ \"$x\" == \"$cur_\"* ]]; then\n+\t\t\tCOMPREPLY[i++]=\"$pfx$x$sfx\"\n+\t\tfi\n+\tdone\n+\tfor x in $2; do\n+\t\tif [[ \"$x\" == \"$cur_\"* ]]; then\n+\t\t\tCOMPREPLY[i++]=\"$pfx$x$sfx2\"\n+\t\tfi\n+\tdone\n+}\n+\n # Generates completion reply with compgen from newline-separated possible\n # completion filenames.\n # It accepts 1 to 3 arguments:\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 6fca145..261a7f5 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -76,6 +76,16 @@ __gitcomp_nl ()\n \tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n }\n \n+__gitcomp_2 ()\n+{\n+\temulate -L zsh\n+\n+\tlocal IFS=$' \\t\\n'\n+\tcompset -P '*[=:]'\n+\tcompadd -Q -S \"${5- }\" -p \"${3-}\" -- ${=1} && _ret=0\n+\tcompadd -Q -S \"${6- }\" -p \"${3-}\" -- ${=2} && _ret=0\n+}\n+\n __gitcomp_file ()\n {\n \temulate -L zsh\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232509","messageId":"1388415138-11011-4-git-send-email-artagnon@gmail.com","threadId":"35585","inReplyTo":"1388415138-11011-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 3/4] completion: fix branch.autosetup(merge|rebase)","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-12-30T14:52:17Z","receivedAt":"2013-12-30T14:52:17Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"When attempting to complete\n\n  $ git config branch.auto<TAB>\n\n'autosetupmerge' and 'autosetuprebase' don't come up. This is because\n\"$cur\" is matched with \"branch.*\" and a list of branches are\ncompleted. Add 'autosetup(merge|rebase)' to the list of branches using\n__gitcomp_2 ().\n\nAlso take care to not complete\n\n  $ git config branch.autosetupmerge.<TAB>\n  $ git config branch.autosetuprebase.<TAB>\n\nwith the usual branch.<name>. candidates.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-completion.bash | 8 +++++++-\n 1 file changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 64b20b8..0bda757 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1851,12 +1851,18 @@ _git_config ()\n \t\t;;\n \tbranch.*.*)\n \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur##*.}\"\n+\t\tif [ \"$pfx\" == \"branch.autosetupmerge.\" ] ||\n+\t\t\t[ \"$pfx\" == \"branch.autosetuprebase.\" ]; then\n+\t\t\treturn\n+\t\tfi\n \t\t__gitcomp \"remote pushremote merge mergeoptions rebase\" \"$pfx\" \"$cur_\"\n \t\treturn\n \t\t;;\n \tbranch.*)\n \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur#*.}\"\n-\t\t__gitcomp_nl \"$(__git_heads)\" \"$pfx\" \"$cur_\" \".\"\n+\t\t__gitcomp_2 \"$(__git_heads)\" \"\n+\t\t\tautosetupmerge autosetuprebase\n+\t\t\t\" \"$pfx\" \"$cur_\" \".\"\n \t\treturn\n \t\t;;\n \tguitool.*.*)\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232508","messageId":"1388415138-11011-5-git-send-email-artagnon@gmail.com","threadId":"35585","inReplyTo":"1388415138-11011-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 4/4] completion: fix remote.pushdefault","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-12-30T14:52:18Z","receivedAt":"2013-12-30T14:52:18Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"When attempting to complete\n\n  $ git config remote.push<TAB>\n\n'pushdefault' doesn't come up. This is because \"$cur\" is matched with\n\"remote.*\" and a list of remotes are completed. Add 'pushdefault' to the\nlist of remotes using __gitcomp_2 ().\n\nAlso take care to not complete\n\n  $ git config remote.pushdefault.<TAB>\n\nwith the usual remote.<name>. candidates.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-completion.bash | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0bda757..9e0213d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1896,6 +1896,9 @@ _git_config ()\n \t\t;;\n \tremote.*.*)\n \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur##*.}\"\n+\t\tif [ \"$pfx\" == \"remote.pushdefault.\" ]; then\n+\t\t\treturn\n+\t\tfi\n \t\t__gitcomp \"\n \t\t\turl proxy fetch push mirror skipDefaultUpdate\n \t\t\treceivepack uploadpack tagopt pushurl\n@@ -1904,7 +1907,7 @@ _git_config ()\n \t\t;;\n \tremote.*)\n \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur#*.}\"\n-\t\t__gitcomp_nl \"$(__git_remotes)\" \"$pfx\" \"$cur_\" \".\"\n+\t\t__gitcomp_2 \"$(__git_remotes)\" \"pushdefault\" \"$pfx\" \"$cur_\" \".\"\n \t\treturn\n \t\t;;\n \turl.*.*)\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232598","messageId":"xmqqeh4qndxs.fsf@gitster.dls.corp.google.com","threadId":"35585","inReplyTo":"1388415138-11011-3-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 2/4] completion: introduce __gitcomp_2 ()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-02T23:47:59Z","receivedAt":"2014-01-02T23:47:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> There are situations where two classes of completions possible. For\n> example\n>\n>   branch.<TAB>\n>\n> should try to complete\n>\n>   branch.master.\n>   branch.autosetupmerge\n>   branch.autosetuprebase\n>\n> The first candidate has the suffix \".\", and the second/ third candidates\n> have the suffix \" \". To facilitate completions of this kind, create a\n> variation of __gitcomp_nl () that accepts two sets of arguments and two\n> independent suffixes.\n\nThat sounds like a reasonable issue to address, but I do not quite\nget why you need a new helper to do this.\n\nIf the original only knows to throw \"branch.\" + branch names +\ntrailing dot into COMPREPLY[] and does so by calling gitcomp_nl,\nisn't it the matter of making another call to gitcomp_nl just after\nthe existing call to stuff branch.autosetup* with trailing SP to\nappend them to COMPREPLY[]?\n\nAhh, is that because the eventual call to __gitcompadd() starts the\niteration starting from zero, essentially forbidding you to\nincrementally adding to COMPREPLY[] from multiple callers, even\nthough it is called comp \"add\" not \"replace with this single thing\"?\n\nWhat I am wondering is if a cleaner solution that can be reused by\nlater needs that may have more than two data sources (or more than\ntwo suffixes) might be to create a variant of __gitcomp_nl that does\nnot clear existing entries in COMPREPLY[] array, add a helper to\nclear the array, which would make the existing one to:\n\n\t__gitcomp_nl () {\n        \t__gitcomp_clear\n                __gitcomp_nl_append \"$@\"\n\t}\n\nand then complete branch.* using two calls to __gitcomp_*, letting\nthe first one clear and later one(s) accumulate:\n\n\t__gitcomp_nl \"$(__git_heads)\" \"$pfx\" \"$cur_\" \".\"\n\t__gitcomp_nl_append $\"autosetupmerge\\nautosetuprebase\\n\" \"$pfx\" \"$cur_\" \" \"\n\nWill queue as-is.\n\nThanks.\n"},{"id":"232599","messageId":"xmqqa9fendj3.fsf@gitster.dls.corp.google.com","threadId":"35585","inReplyTo":"1388415138-11011-4-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 3/4] completion: fix branch.autosetup(merge|rebase)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-02T23:56:48Z","receivedAt":"2014-01-02T23:56:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n>  \tbranch.*.*)\n>  \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur##*.}\"\n> +\t\tif [ \"$pfx\" == \"branch.autosetupmerge.\" ] ||\n> +\t\t\t[ \"$pfx\" == \"branch.autosetuprebase.\" ]; then\n> +\t\t\treturn\n> +\t\tfi\n>  \t\t__gitcomp \"remote pushremote merge mergeoptions rebase\" \"$pfx\" \"$cur_\"\n>  \t\treturn\n>  \t\t;;\n\nI do not quite understand this change.\n\nIf we are looking at \"branch.autosetupmerge.\" followed by something,\nwho typed that final dot?  If you are working on a topic about\nauto-setup-merge and named your branch \"autosetupmerge\", don't you\nwant to be able to configure various aspect of that branch via\nbranch.autosetupmerge.{remote,merge} etc., just like you can do so\nfor your \"topic\" branch via branch.topic.{remote,merge} etc.,\nregardless of your use of \"autosetupmerge\" option across branches?\n\nBesides, it smells fishy to me that you need to enumerate and\nspecial case these two here, and then you have to repeat them below\nin a separate case arm.\n\n>  \tbranch.*)\n>  \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur#*.}\"\n> -\t\t__gitcomp_nl \"$(__git_heads)\" \"$pfx\" \"$cur_\" \".\"\n> +\t\t__gitcomp_2 \"$(__git_heads)\" \"\n> +\t\t\tautosetupmerge autosetuprebase\n> +\t\t\t\" \"$pfx\" \"$cur_\" \".\"\n>  \t\treturn\n>  \t\t;;\n>  \tguitool.*.*)\n"},{"id":"232607","messageId":"CALkWK0=tL4K7UHDBp_jGz5zUaHE9m=OESo2=2a0fUZwXB4auGg@mail.gmail.com","threadId":"35585","inReplyTo":"xmqqa9fendj3.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 3/4] completion: fix branch.autosetup(merge|rebase)","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T07:36:27Z","receivedAt":"2014-01-03T07:36:27Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> If we are looking at \"branch.autosetupmerge.\" followed by something,\n> who typed that final dot?\n\nI admit that it's a very unlikely case. The user did:\n\n  $ branch.autosetupmer<TAB>\n\nhit backspace to delete the trailing space, inserted a dot, and hit <TAB> again.\n\n> If you are working on a topic about\n> auto-setup-merge and named your branch \"autosetupmerge\", don't you\n> want to be able to configure various aspect of that branch via\n> branch.autosetupmerge.{remote,merge} etc., just like you can do so\n> for your \"topic\" branch via branch.topic.{remote,merge} etc.,\n> regardless of your use of \"autosetupmerge\" option across branches?\n\nMy reasoning was that being correct was more important that being\ncomplete. So, if by some horrible chance, the user names her branch\n\"autosetupmerge\", we don't aid her in completions.\n\n> Besides, it smells fishy to me that you need to enumerate and\n> special case these two here, and then you have to repeat them below\n> in a separate case arm.\n\nI'm not too irked about correctness in this odd case; seeing that you\naren't either, I'll resubmit the series without this hunk (+ the hunk\nin remote.pushdefault).\n"},{"id":"232608","messageId":"CALkWK0mgqJFz1Lf_UVX8fdvnT+u+rp705dak7kXVFFBSr2bTQA@mail.gmail.com","threadId":"35585","inReplyTo":"xmqqeh4qndxs.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 2/4] completion: introduce __gitcomp_2 ()","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T07:51:17Z","receivedAt":"2014-01-03T07:51:17Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n>         __gitcomp_nl \"$(__git_heads)\" \"$pfx\" \"$cur_\" \".\"\n>         __gitcomp_nl_append $\"autosetupmerge\\nautosetuprebase\\n\" \"$pfx\" \"$cur_\" \" \"\n\nThis is not a bad idea at all. I'm just afraid that we might be\nleaving open ends: What happens if the $pfx isn't the same in both\ncases? Who keeps track of the index \"i\" of COMPREPLY (it's currently a\nlocal variable)? If we make it global, doesn't every function that\ndeals with COMPREPLY be careful to reset it?\n\nMore importantly, can you see a usecase for more than two completion classes?\n"},{"id":"232619","messageId":"xmqq1u0pnf7b.fsf@gitster.dls.corp.google.com","threadId":"35585","inReplyTo":"CALkWK0=tL4K7UHDBp_jGz5zUaHE9m=OESo2=2a0fUZwXB4auGg@mail.gmail.com","subject":"Re: [PATCH 3/4] completion: fix branch.autosetup(merge|rebase)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-03T17:32:56Z","receivedAt":"2014-01-03T17:32:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>> If we are looking at \"branch.autosetupmerge.\" followed by something,\n>> who typed that final dot?\n>\n> I admit that it's a very unlikely case. The user did:\n>\n>   $ branch.autosetupmer<TAB>\n>\n> hit backspace to delete the trailing space, inserted a dot, and hit <TAB> again.\n>\n>> If you are working on a topic about\n>> auto-setup-merge and named your branch \"autosetupmerge\", don't you\n>> want to be able to configure various aspect of that branch via\n>> branch.autosetupmerge.{remote,merge} etc., just like you can do so\n>> for your \"topic\" branch via branch.topic.{remote,merge} etc.,\n>> regardless of your use of \"autosetupmerge\" option across branches?\n>\n> My reasoning was that being correct was more important that being\n> complete. So, if by some horrible chance, the user names her branch\n> \"autosetupmerge\", we don't aid her in completions.\n>\n>> Besides, it smells fishy to me that you need to enumerate and\n>> special case these two here, and then you have to repeat them below\n>> in a separate case arm.\n>\n> I'm not too irked about correctness in this odd case; seeing that you\n> aren't either, I'll resubmit the series without this hunk (+ the hunk\n> in remote.pushdefault).\n\nYou seem to be calling it \"incorrect\" to give the same degree of\ncompletion for a branch the user named \"autosetupmerge\" as another\nbranch \"topic\", but I think it is incorrect not to, so I cannot tell\nif we are agreeing or disagreeing.\n\nPuzzled...\n"},{"id":"232620","messageId":"xmqqwqihlzuj.fsf@gitster.dls.corp.google.com","threadId":"35585","inReplyTo":"CALkWK0mgqJFz1Lf_UVX8fdvnT+u+rp705dak7kXVFFBSr2bTQA@mail.gmail.com","subject":"Re: [PATCH 2/4] completion: introduce __gitcomp_2 ()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-03T17:49:55Z","receivedAt":"2014-01-03T17:49:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>>         __gitcomp_nl \"$(__git_heads)\" \"$pfx\" \"$cur_\" \".\"\n>>         __gitcomp_nl_append $\"autosetupmerge\\nautosetuprebase\\n\" \"$pfx\" \"$cur_\" \" \"\n>\n> This is not a bad idea at all. I'm just afraid that we might be\n> leaving open ends: What happens if the $pfx isn't the same in both\n> cases? Who keeps track of the index \"i\" of COMPREPLY (it's currently a\n> local variable)? If we make it global, doesn't every function that\n> deals with COMPREPLY be careful to reset it?\n\nI am not sure what you are worried about $pfx; what does it do when\nyou have strings with different prefix in COMPREPLY? If it breaks,\nthen the answer is \"don't do it then\".\n\nDoesn't an array know its own length and give you a way to ask?\n\n> More importantly, can you see a usecase for more than two completion classes?\n\nI am not sure why you think it is more important.\n\nSomebody lacked forsight and designed an interface that would allow\nonly one \"completion classes\" (whatever that means) and called the\nresult sufficient. It has been sufficient for a long time.\n\nLater you came, found that one was not enough, and added an inteface\nthat would allow only two, and called the result sufficient.  See a\npattern?\n\nAnticipating unforseen possibilities for enhancement and preparing\nan easy way to support them without overengineering is what the\n\"prepare an appending variant\" suggestion is about, and by\ndefinition, unforseen possibilities have not been seen yet ;-)\n\nImagine if one is flipping 47 topic branches from 6 contributors\nwhose names all begin with 'j'.  I can see that such a person would\nappreciate if \"git config branch.j<TAB>\" did not dump all 47 topics\nat once but offered \"jc/ jk/ jl/ jm/ jn/ js/\" instead, and then a\nfollow-up completion of \"git config branch.jk/<TAB>\" expanded to\nnames of topics from that single contributor \"jk\".  Wouldn't the way\nto give these be either to return these two-letter hierarchy names\nwith slash as the suffix or to return list of two-letter plus a\nslash with an empty suffix?  Either way, that is using something\ndifferent from a dot or a space, so that may count as the third, I\nguess.\n"},{"id":"232627","messageId":"CALkWK0mGJ2V9V=KzuaAraNX-edEVBEpp-9DcAaBF-dZCqp6bsw@mail.gmail.com","threadId":"35585","inReplyTo":"xmqq1u0pnf7b.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 3/4] completion: fix branch.autosetup(merge|rebase)","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T18:58:31Z","receivedAt":"2014-01-03T18:58:31Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> You seem to be calling it \"incorrect\" to give the same degree of\n> completion for a branch the user named \"autosetupmerge\" as another\n> branch \"topic\", but I think it is incorrect not to, so I cannot tell\n> if we are agreeing or disagreeing.\n\nNo, what's incorrect is providing completions for\n\n  $ git config branch.autosetupmerge.<TAB>\n\nwhen no branch called \"autosetupmerge\" exists. The purpose of the hunk\n(which I now removed) was to prevent such completions, but it has the\nside-effect of also preventing a legitimate completion in the case\nwhen the user really has a branch named \"autosetupmerge\".\n\nWhat is your take on the issue?\n"},{"id":"232629","messageId":"CALkWK0nQ30fg0RjgKq9WSb2Mv9W8xQsK+wy9hzHt7RGpBbad-Q@mail.gmail.com","threadId":"35585","inReplyTo":"xmqqwqihlzuj.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 2/4] completion: introduce __gitcomp_2 ()","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T19:09:24Z","receivedAt":"2014-01-03T19:09:24Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> I am not sure what you are worried about $pfx; what does it do when\n> you have strings with different prefix in COMPREPLY? If it breaks,\n> then the answer is \"don't do it then\".\n>\n> Doesn't an array know its own length and give you a way to ask?\n\nRight. I was just throwing counterpoints at the wall.\n\n> Imagine if one is flipping 47 topic branches from 6 contributors\n> whose names all begin with 'j'.  I can see that such a person would\n> appreciate if \"git config branch.j<TAB>\" did not dump all 47 topics\n> at once but offered \"jc/ jk/ jl/ jm/ jn/ js/\" instead, and then a\n> follow-up completion of \"git config branch.jk/<TAB>\" expanded to\n> names of topics from that single contributor \"jk\".  Wouldn't the way\n> to give these be either to return these two-letter hierarchy names\n> with slash as the suffix or to return list of two-letter plus a\n> slash with an empty suffix?  Either way, that is using something\n> different from a dot or a space, so that may count as the third, I\n> guess.\n\nAh, after completing branch.jk/, we would want no suffix: so the\nexample definitely counts as a third \"completion class\". I agree with\nyour reasoning, and will rework the series to do the _append () thing\nyou suggested.\n\nThanks.\n"},{"id":"232630","messageId":"xmqqa9fcnajr.fsf@gitster.dls.corp.google.com","threadId":"35585","inReplyTo":"CALkWK0mGJ2V9V=KzuaAraNX-edEVBEpp-9DcAaBF-dZCqp6bsw@mail.gmail.com","subject":"Re: [PATCH 3/4] completion: fix branch.autosetup(merge|rebase)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-03T19:13:28Z","receivedAt":"2014-01-03T19:13:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>> You seem to be calling it \"incorrect\" to give the same degree of\n>> completion for a branch the user named \"autosetupmerge\" as another\n>> branch \"topic\", but I think it is incorrect not to, so I cannot tell\n>> if we are agreeing or disagreeing.\n>\n> No, what's incorrect is providing completions for\n>\n>   $ git config branch.autosetupmerge.<TAB>\n>\n> when no branch called \"autosetupmerge\" exists.  The purpose of the\n> hunk (which I now removed) was to prevent such completions, ...\n\nHmph, but in a repository without 'foo', I just did\n\n\t$ git config branch.foo.<TAB>\n        branch.foo.merge          branch.foo.rebase         \n        branch.foo.mergeoptions   branch.foo.remote         \n\nand got offered the above. How would that removed hunk that special\ncased those autosetupmerge etc. helped such case?\n\nIf it _were_ about correctness, and the definition of correctness\nwere that \"completing branch.foo.<TAB> to offer these four variables\nis wrong until refs/heads/foo materializes\", the \"fix\" would have\nchecked if there already is such a branch and refused to complete\notherwise, not special case a few known names such as autosetup*.\n\nAs there is no reason to forbid setting configuration variables for\na branch 'foo' you are going to create before you actually create it\nwith \"git branch foo\", I do not necessarily agree with the above\ndefinition of correctness, either.\n\nSo it was completely bogus hunk and it is good we noticed and\ndecided to remove it, I guess.\n"}]}