@matheusbsbs / matheus-bagliano / commits / d447fe2bfe
Fork 0

completion: clean up the __git_find_on_cmdline() helper function

The __git_find_on_cmdline() helper function started its life as __git_find_subcommand() [1], but it served a more general purpose than looking for subcommands, so later it was renamed accordingly [2]. However, that rename didn't touch the body of the function, and left the $subcommand local variable behind, still reminiscent of the function's original purpose. Let's clean up the names of __git_find_on_cmdline()'s local variables and get rid of that $subcommand variable name. While at it, add a short comment describing the function's purpose. [1] 3ff1320d4b (bash: refactor searching for subcommands on the command line, 2008-03-10), [2] 918c03c2a7 (bash: rename __git_find_subcommand() to __git_find_on_cmdline(), 2009-09-15) Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Dec 19, 2019 at 16:09 UTC d447fe2bfe68840cb127fbbc9fc3a53faab2124b
1 file changed +8 -5
contrib/completion/git-completion.bash
+8 -5
@@ -1070,14 +1070,17 @@ __git_aliased_command ()
1070 }
1071
1072 # __git_find_on_cmdline requires 1 argument
1073 +# Check whether one of the given words is present on the command line,
1074 +# and print the first word found.
1075 __git_find_on_cmdline ()
1076 {
1075 - local word subcommand c=1
1077 + local word c=1
1078 + local wordlist="$1"
1079 +
1080 while [ $c -lt $cword ]; do
1077 - word="${words[c]}"
1078 - for subcommand in $1; do
1079 - if [ "$subcommand" = "$word" ]; then
1080 - echo "$subcommand"
1081 + for word in $wordlist; do
1082 + if [ "$word" = "${words[c]}" ]; then
1083 + echo "$word"
1084 return
1085 fi
1086 done