{"thread":{"id":"35604","subject":"[PATCH v3 0/4] Fix branch.autosetup(merge|rebase) completion","startedAt":"2014-01-03T19:56:58Z","lastAt":"2014-01-05T10:06:21Z","messageCount":8,"participants":["Ramkumar Ramachandra","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":4},"messages":[{"id":"232631","messageId":"1388779022-14536-1-git-send-email-artagnon@gmail.com","threadId":"35604","inReplyTo":null,"subject":"[PATCH v3 0/4] Fix branch.autosetup(merge|rebase) completion","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T19:56:58Z","receivedAt":"2014-01-03T19:56:58Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Junio et al,\n\nIn v3, I've implemented __gitcomp_nl_append (), like you\nsuggested. After implementing it, I feel foolish about having gone\naround my head to do __gitcomp_2 ().\n\nThanks.\n\nRamkumar Ramachandra (4):\n  completion: prioritize ./git-completion.bash\n  completion: introduce __gitcomp_nl_append ()\n  completion: fix branch.autosetup(merge|rebase)\n  completion: fix remote.pushdefault\n\n contrib/completion/git-completion.bash | 15 +++++++++++++++\n contrib/completion/git-completion.zsh  | 10 +++++++++-\n 2 files changed, 24 insertions(+), 1 deletion(-)\n\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232632","messageId":"1388779022-14536-2-git-send-email-artagnon@gmail.com","threadId":"35604","inReplyTo":"1388779022-14536-1-git-send-email-artagnon@gmail.com","subject":"[PATCH v3 1/4] completion: prioritize ./git-completion.bash","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T19:56:59Z","receivedAt":"2014-01-03T19:56:59Z","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":"232635","messageId":"1388779022-14536-3-git-send-email-artagnon@gmail.com","threadId":"35604","inReplyTo":"1388779022-14536-1-git-send-email-artagnon@gmail.com","subject":"[PATCH v3 2/4] completion: introduce __gitcomp_nl_append ()","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T19:57:00Z","receivedAt":"2014-01-03T19:57:00Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"There are situations where multiple 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 appends to the existing list of\ncompletion candidates, COMPREPLY.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-completion.bash | 13 +++++++++++++\n contrib/completion/git-completion.zsh  |  8 ++++++++\n 2 files changed, 21 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 51c2dd4..bf358d6 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -233,6 +233,19 @@ __gitcomp_nl ()\n \t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n }\n \n+# Variation of __gitcomp_nl () that appends to the existing list of\n+# completion candidates, COMPREPLY.\n+__gitcomp_nl_append ()\n+{\n+\tlocal IFS=$'\\n'\n+\tlocal i=${#COMPREPLY[@]}\n+\tfor x in $1; do\n+\t\tif [[ \"$x\" == \"$3\"* ]]; then\n+\t\t\tCOMPREPLY[i++]=\"$2$x$4\"\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..6b77968 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -76,6 +76,14 @@ __gitcomp_nl ()\n \tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n }\n \n+__gitcomp_nl_append ()\n+{\n+\temulate -L zsh\n+\n+\tlocal IFS=$'\\n'\n+\tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n+}\n+\n __gitcomp_file ()\n {\n \temulate -L zsh\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232633","messageId":"1388779022-14536-4-git-send-email-artagnon@gmail.com","threadId":"35604","inReplyTo":"1388779022-14536-1-git-send-email-artagnon@gmail.com","subject":"[PATCH v3 3/4] completion: fix branch.autosetup(merge|rebase)","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T19:57:01Z","receivedAt":"2014-01-03T19:57:01Z","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 'autosetupmerge', 'autosetuprebase' to the list of\nbranches using __gitcomp_nl_append ().\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-completion.bash | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex bf358d6..75c7302 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1840,6 +1840,7 @@ _git_config ()\n \tbranch.*)\n \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur#*.}\"\n \t\t__gitcomp_nl \"$(__git_heads)\" \"$pfx\" \"$cur_\" \".\"\n+\t\t__gitcomp_nl_append $'autosetupmerge\\nautosetuprebase\\n' \"$pfx\" \"$cur_\"\n \t\treturn\n \t\t;;\n \tguitool.*.*)\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232634","messageId":"1388779022-14536-5-git-send-email-artagnon@gmail.com","threadId":"35604","inReplyTo":"1388779022-14536-1-git-send-email-artagnon@gmail.com","subject":"[PATCH v3 4/4] completion: fix remote.pushdefault","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-03T19:57:02Z","receivedAt":"2014-01-03T19:57:02Z","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_nl_append ().\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-completion.bash | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 75c7302..345ceff 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1883,6 +1883,7 @@ _git_config ()\n \tremote.*)\n \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur#*.}\"\n \t\t__gitcomp_nl \"$(__git_remotes)\" \"$pfx\" \"$cur_\" \".\"\n+\t\t__gitcomp_nl_append \"pushdefault\" \"$pfx\" \"$cur_\"\n \t\treturn\n \t\t;;\n \turl.*.*)\n-- \n1.8.5.2.227.g53f3478\n"},{"id":"232639","messageId":"xmqq38l4n6h9.fsf@gitster.dls.corp.google.com","threadId":"35604","inReplyTo":"1388779022-14536-3-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH v3 2/4] completion: introduce __gitcomp_nl_append ()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-03T20:41:22Z","receivedAt":"2014-01-03T20:41:22Z","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> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 51c2dd4..bf358d6 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -233,6 +233,19 @@ __gitcomp_nl ()\n>  \t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n>  }\n>  \n> +# Variation of __gitcomp_nl () that appends to the existing list of\n> +# completion candidates, COMPREPLY.\n> +__gitcomp_nl_append ()\n> +{\n> +\tlocal IFS=$'\\n'\n> +\tlocal i=${#COMPREPLY[@]}\n> +\tfor x in $1; do\n> +\t\tif [[ \"$x\" == \"$3\"* ]]; then\n> +\t\t\tCOMPREPLY[i++]=\"$2$x$4\"\n> +\t\tfi\n> +\tdone\n> +}\n\nHmph. Why so much duplication with __gitcompadd, though.\n\nI would have expected that this \"append\" behaviour to be done at the\nlower level by introducing __gitcompappend that does not forcibly\ntruncate by starting from a hard-coded i=0, i.e. a collection of\nsmall helper functions plus a single implementation of the logic to\npush elements into COMPREPLY[] in __gitcompappend, perhaps like\nthese:\n\n\t__gitcompappend () {\n\t\tlocal i=${#COMPREPLY[@]}\n\t\tfor x in $1; do\n                        if [[ \"$x\" == \"$3\"* ]]; then\n                                COMPREPLY[i++]=\"$2$x$4\"\n                        fi\n\t\tdone\n        }\n\n\t__gitcompadd () {\n\t\tCOMPREPLY=()\n\t\t__gitcompappend \"$@\"\n\t}\n\n\t__gitcomp_nl_append () {\n\t\tlocal IFS=$'\\n'\n                __gitcompappend \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n        }\n\n\t__gitcomp_nl () {\n\t\tCOMPREPLY=()\n                __gitcomp_nl_append \"$@\"\t\t\n        }\n        \nIs it because going this route and doing it at such a low level\nwould make zsh completion (which I have no clue about ;-)\nunnecessarily complex?\n\n> +\n>  # Generates completion reply with compgen from newline-separated possible\n>  # completion filenames.\n>  # It accepts 1 to 3 arguments:\n> diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\n> index 6fca145..6b77968 100644\n> --- a/contrib/completion/git-completion.zsh\n> +++ b/contrib/completion/git-completion.zsh\n> @@ -76,6 +76,14 @@ __gitcomp_nl ()\n>  \tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n>  }\n>  \n> +__gitcomp_nl_append ()\n> +{\n> +\temulate -L zsh\n> +\n> +\tlocal IFS=$'\\n'\n> +\tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n> +}\n> +\n>  __gitcomp_file ()\n>  {\n>  \temulate -L zsh\n"},{"id":"232641","messageId":"xmqqy52wlq2k.fsf@gitster.dls.corp.google.com","threadId":"35604","inReplyTo":"1388779022-14536-5-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH v3 4/4] completion: fix remote.pushdefault","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-03T21:21:07Z","receivedAt":"2014-01-03T21:21:07Z","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> 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\n> list of remotes using __gitcomp_nl_append ().\n\n\"Add ... to the list of remotes\" (same for \"list of branches\" in\n3/4) sounds somewhat funny, doesn't it?  How about\n\n\tAdd remote.pushdefault as a candidate for completion, too.\n\nor something like that instead?\n\n>\n> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n> ---\n>  contrib/completion/git-completion.bash | 1 +\n>  1 file changed, 1 insertion(+)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 75c7302..345ceff 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1883,6 +1883,7 @@ _git_config ()\n>  \tremote.*)\n>  \t\tlocal pfx=\"${cur%.*}.\" cur_=\"${cur#*.}\"\n>  \t\t__gitcomp_nl \"$(__git_remotes)\" \"$pfx\" \"$cur_\" \".\"\n> +\t\t__gitcomp_nl_append \"pushdefault\" \"$pfx\" \"$cur_\"\n>  \t\treturn\n>  \t\t;;\n>  \turl.*.*)\n"},{"id":"232661","messageId":"CALkWK0=rrcTFdpymGB5QJhdLhYvm4FLMGurqugbCGvAdDKVhqA@mail.gmail.com","threadId":"35604","inReplyTo":"xmqq38l4n6h9.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v3 2/4] completion: introduce __gitcomp_nl_append ()","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2014-01-05T10:06:21Z","receivedAt":"2014-01-05T10:06:21Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> Is it because going this route and doing it at such a low level\n> would make zsh completion (which I have no clue about ;-)\n> unnecessarily complex?\n\nThe zsh completion only cares to override __gitcomp_nl () and\n__gitcomp_nl_append (), without bothering to re-implement the\nlower-level functions; so it's no problem at all. I wrote mine out by\nthinking of a non-intrusive direct translation, while your version\nfocuses on eliminating duplication. I don't have a strong preference\neither way, so I will resubmit with your version.\n"}]}