{"thread":{"id":"29471","subject":"[PATCH] completion: cleanup __gitcomp*","startedAt":"2012-01-30T00:29:31Z","lastAt":"2012-01-30T03:39:20Z","messageCount":3,"participants":["Felipe Contreras","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"183274","messageId":"1327883371-25573-1-git-send-email-felipe.contreras@gmail.com","threadId":"29471","inReplyTo":null,"subject":"[PATCH] completion: cleanup __gitcomp*","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-30T00:29:31Z","receivedAt":"2012-01-30T00:29:31Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"I don't know why there's so much code; these functions don't seem to be\ndoing much:\n\n * ${1-} is the same as $1\n * no need to check $#, ${3:-$cur} is much easier\n * __gitcomp_nl doesn't seem to using the initial IFS\n\nThis makes the code much simpler.\n\nEventually it would be nice to wrap everything that touches compgen and\nCOMPREPLY in one function for the zsh wrapper.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |   24 +++++-------------------\n 1 files changed, 5 insertions(+), 19 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 1496c6d..accfce5 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -495,19 +495,15 @@ fi\n # 4: A suffix to be appended to each possible completion word (optional).\n __gitcomp ()\n {\n-\tlocal cur_=\"$cur\"\n-\n-\tif [ $# -gt 2 ]; then\n-\t\tcur_=\"$3\"\n-\tfi\n+\tlocal cur_=\"${3:-$cur}\"\n \tcase \"$cur_\" in\n \t--*=)\n \t\tCOMPREPLY=()\n \t\t;;\n \t*)\n \t\tlocal IFS=$'\\n'\n-\t\tCOMPREPLY=($(compgen -P \"${2-}\" \\\n-\t\t\t-W \"$(__gitcomp_1 \"${1-}\" \"${4-}\")\" \\\n+\t\tCOMPREPLY=($(compgen -P \"$2\" \\\n+\t\t\t-W \"$(__gitcomp_1 \"$1\" \"$4\")\" \\\n \t\t\t-- \"$cur_\"))\n \t\t;;\n \tesac\n@@ -524,18 +520,8 @@ __gitcomp ()\n #    appended.\n __gitcomp_nl ()\n {\n-\tlocal s=$'\\n' IFS=' '$'\\t'$'\\n'\n-\tlocal cur_=\"$cur\" suffix=\" \"\n-\n-\tif [ $# -gt 2 ]; then\n-\t\tcur_=\"$3\"\n-\t\tif [ $# -gt 3 ]; then\n-\t\t\tsuffix=\"$4\"\n-\t\tfi\n-\tfi\n-\n-\tIFS=$s\n-\tCOMPREPLY=($(compgen -P \"${2-}\" -S \"$suffix\" -W \"$1\" -- \"$cur_\"))\n+\tlocal IFS=$'\\n'\n+\tCOMPREPLY=($(compgen -P \"$2\" -S \"${4:- }\" -W \"$1\" -- \"${3:-$cur}\"))\n }\n \n __git_heads ()\n-- \n1.7.8.3\n"},{"id":"183276","messageId":"20120130024242.GA15896@burratino","threadId":"29471","inReplyTo":"1327883371-25573-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] completion: cleanup __gitcomp*","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-01-30T02:42:42Z","receivedAt":"2012-01-30T02:42:42Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Felipe Contreras wrote:\n\n>  * ${1-} is the same as $1\n\n| $ git log -S'${1-}' contrib/completion/git-completion.bash\n| [...]\n| commit 25a31f81\n| Author: Ted Pavlic <ted@tedpavlic.com>\n| Date:   Thu Jan 15 11:02:21 2009 -0500\n|\n|     bash-completion: Support running when set -u is enabled\n|\n|     Under \"set -u\" semantics, it is an error to access undefined variables.\n|     Some user environments may enable this setting in the interactive shell.\n|\n|     In any context where the completion functions access an undefined\n|     variable, accessing a default empty string (aka \"${1-}\" instead of \"$1\")\n|     is a reasonable way to code the function, as it silences the undefined\n|     variable error while still supplying an empty string.\n|\n|     In this patch, functions that should always take an argument still use\n|     $1. Functions that have optional arguments use ${1-}.\n|\n|     Signed-off-by: Ted Pavlic <ted@tedpavlic.com>\n|     Acked-by: Shawn O. Pearce <spearce@spearce.org>\n|     Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nHope that helps,\nJonathan\n"},{"id":"183282","messageId":"CAMP44s2pUwjvLCfjoh1kjxeBYz1v3=7A19hOZMUHgfTWkP-eqg@mail.gmail.com","threadId":"29471","inReplyTo":"20120130024242.GA15896@burratino","subject":"Re: [PATCH] completion: cleanup __gitcomp*","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-30T03:39:20Z","receivedAt":"2012-01-30T03:39:20Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Mon, Jan 30, 2012 at 4:42 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Felipe Contreras wrote:\n>\n>>  * ${1-} is the same as $1\n>\n> | $ git log -S'${1-}' contrib/completion/git-completion.bash\n> | [...]\n> | commit 25a31f81\n> | Author: Ted Pavlic <ted@tedpavlic.com>\n> | Date:   Thu Jan 15 11:02:21 2009 -0500\n> |\n> |     bash-completion: Support running when set -u is enabled\n> |\n> |     Under \"set -u\" semantics, it is an error to access undefined variables.\n> |     Some user environments may enable this setting in the interactive shell.\n> |\n> |     In any context where the completion functions access an undefined\n> |     variable, accessing a default empty string (aka \"${1-}\" instead of \"$1\")\n> |     is a reasonable way to code the function, as it silences the undefined\n> |     variable error while still supplying an empty string.\n> |\n> |     In this patch, functions that should always take an argument still use\n> |     $1. Functions that have optional arguments use ${1-}.\n> |\n> |     Signed-off-by: Ted Pavlic <ted@tedpavlic.com>\n> |     Acked-by: Shawn O. Pearce <spearce@spearce.org>\n> |     Signed-off-by: Junio C Hamano <gitster@pobox.com>\n>\n> Hope that helps,\n\nI see. I'll revert that then.\n\n-- \nFelipe Contreras\n"}]}