completion: don't modify the $cur variable in completion functions
Since v1.7.4-rc0~11^2~2 (bash: get --pretty=m<tab> completion to work with bash v4, 2010-12-02) we use _get_comp_words_by_ref() to access completion-related variables, and the $cur variable holds the word containing the current cursor position in all completion functions. This $cur variable is left unchanged in most completion functions; there are only four functions modifying its value, namely __gitcomp(), __git_complete_revlist_file(), __git_complete_remote_or_refspec(), and _git_config(). If this variable were never modified, then it would allow us a nice optimisation and cleanup. Therefore, this patch assigns $cur to an other local variable and uses that for later modifications in those four functions. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e839fe6c12
commit
9244d69b96
@ -491,10 +491,12 @@ __gitcomp ()
|
|||||||
{
|
{
|
||||||
local cur
|
local cur
|
||||||
_get_comp_words_by_ref -n =: cur
|
_get_comp_words_by_ref -n =: cur
|
||||||
|
local cur_="$cur"
|
||||||
|
|
||||||
if [ $# -gt 2 ]; then
|
if [ $# -gt 2 ]; then
|
||||||
cur="$3"
|
cur_="$3"
|
||||||
fi
|
fi
|
||||||
case "$cur" in
|
case "$cur_" in
|
||||||
--*=)
|
--*=)
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
;;
|
;;
|
||||||
@ -502,7 +504,7 @@ __gitcomp ()
|
|||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
COMPREPLY=($(compgen -P "${2-}" \
|
COMPREPLY=($(compgen -P "${2-}" \
|
||||||
-W "$(__gitcomp_1 "${1-}" "${4-}")" \
|
-W "$(__gitcomp_1 "${1-}" "${4-}")" \
|
||||||
-- "$cur"))
|
-- "$cur_"))
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -668,17 +670,18 @@ __git_complete_revlist_file ()
|
|||||||
{
|
{
|
||||||
local pfx ls ref cur
|
local pfx ls ref cur
|
||||||
_get_comp_words_by_ref -n =: cur
|
_get_comp_words_by_ref -n =: cur
|
||||||
case "$cur" in
|
local cur_="$cur"
|
||||||
|
case "$cur_" in
|
||||||
*..?*:*)
|
*..?*:*)
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
?*:*)
|
?*:*)
|
||||||
ref="${cur%%:*}"
|
ref="${cur_%%:*}"
|
||||||
cur="${cur#*:}"
|
cur_="${cur_#*:}"
|
||||||
case "$cur" in
|
case "$cur_" in
|
||||||
?*/*)
|
?*/*)
|
||||||
pfx="${cur%/*}"
|
pfx="${cur_%/*}"
|
||||||
cur="${cur##*/}"
|
cur_="${cur_##*/}"
|
||||||
ls="$ref:$pfx"
|
ls="$ref:$pfx"
|
||||||
pfx="$pfx/"
|
pfx="$pfx/"
|
||||||
;;
|
;;
|
||||||
@ -708,17 +711,17 @@ __git_complete_revlist_file ()
|
|||||||
s,$,/,
|
s,$,/,
|
||||||
}
|
}
|
||||||
s/^.* //')" \
|
s/^.* //')" \
|
||||||
-- "$cur"))
|
-- "$cur_"))
|
||||||
;;
|
;;
|
||||||
*...*)
|
*...*)
|
||||||
pfx="${cur%...*}..."
|
pfx="${cur_%...*}..."
|
||||||
cur="${cur#*...}"
|
cur_="${cur_#*...}"
|
||||||
__gitcomp "$(__git_refs)" "$pfx" "$cur"
|
__gitcomp "$(__git_refs)" "$pfx" "$cur_"
|
||||||
;;
|
;;
|
||||||
*..*)
|
*..*)
|
||||||
pfx="${cur%..*}.."
|
pfx="${cur_%..*}.."
|
||||||
cur="${cur#*..}"
|
cur_="${cur_#*..}"
|
||||||
__gitcomp "$(__git_refs)" "$pfx" "$cur"
|
__gitcomp "$(__git_refs)" "$pfx" "$cur_"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__gitcomp "$(__git_refs)"
|
__gitcomp "$(__git_refs)"
|
||||||
@ -741,7 +744,7 @@ __git_complete_remote_or_refspec ()
|
|||||||
{
|
{
|
||||||
local cur words cword
|
local cur words cword
|
||||||
_get_comp_words_by_ref -n =: cur words cword
|
_get_comp_words_by_ref -n =: cur words cword
|
||||||
local cmd="${words[1]}"
|
local cur_="$cur" cmd="${words[1]}"
|
||||||
local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
|
local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
|
||||||
while [ $c -lt $cword ]; do
|
while [ $c -lt $cword ]; do
|
||||||
i="${words[c]}"
|
i="${words[c]}"
|
||||||
@ -771,40 +774,40 @@ __git_complete_remote_or_refspec ()
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
[ "$remote" = "." ] && remote=
|
[ "$remote" = "." ] && remote=
|
||||||
case "$cur" in
|
case "$cur_" in
|
||||||
*:*)
|
*:*)
|
||||||
case "$COMP_WORDBREAKS" in
|
case "$COMP_WORDBREAKS" in
|
||||||
*:*) : great ;;
|
*:*) : great ;;
|
||||||
*) pfx="${cur%%:*}:" ;;
|
*) pfx="${cur_%%:*}:" ;;
|
||||||
esac
|
esac
|
||||||
cur="${cur#*:}"
|
cur_="${cur_#*:}"
|
||||||
lhs=0
|
lhs=0
|
||||||
;;
|
;;
|
||||||
+*)
|
+*)
|
||||||
pfx="+"
|
pfx="+"
|
||||||
cur="${cur#+}"
|
cur_="${cur_#+}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
fetch)
|
fetch)
|
||||||
if [ $lhs = 1 ]; then
|
if [ $lhs = 1 ]; then
|
||||||
__gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
|
__gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur_"
|
||||||
else
|
else
|
||||||
__gitcomp "$(__git_refs)" "$pfx" "$cur"
|
__gitcomp "$(__git_refs)" "$pfx" "$cur_"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
pull)
|
pull)
|
||||||
if [ $lhs = 1 ]; then
|
if [ $lhs = 1 ]; then
|
||||||
__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
|
__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur_"
|
||||||
else
|
else
|
||||||
__gitcomp "$(__git_refs)" "$pfx" "$cur"
|
__gitcomp "$(__git_refs)" "$pfx" "$cur_"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
push)
|
push)
|
||||||
if [ $lhs = 1 ]; then
|
if [ $lhs = 1 ]; then
|
||||||
__gitcomp "$(__git_refs)" "$pfx" "$cur"
|
__gitcomp "$(__git_refs)" "$pfx" "$cur_"
|
||||||
else
|
else
|
||||||
__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
|
__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur_"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -2012,70 +2015,60 @@ _git_config ()
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
branch.*.*)
|
branch.*.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur##*.}"
|
||||||
cur="${cur##*.}"
|
__gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
|
||||||
__gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
branch.*)
|
branch.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur#*.}"
|
||||||
cur="${cur#*.}"
|
__gitcomp "$(__git_heads)" "$pfx" "$cur_" "."
|
||||||
__gitcomp "$(__git_heads)" "$pfx" "$cur" "."
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
guitool.*.*)
|
guitool.*.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur##*.}"
|
||||||
cur="${cur##*.}"
|
|
||||||
__gitcomp "
|
__gitcomp "
|
||||||
argprompt cmd confirm needsfile noconsole norescan
|
argprompt cmd confirm needsfile noconsole norescan
|
||||||
prompt revprompt revunmerged title
|
prompt revprompt revunmerged title
|
||||||
" "$pfx" "$cur"
|
" "$pfx" "$cur_"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
difftool.*.*)
|
difftool.*.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur##*.}"
|
||||||
cur="${cur##*.}"
|
__gitcomp "cmd path" "$pfx" "$cur_"
|
||||||
__gitcomp "cmd path" "$pfx" "$cur"
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
man.*.*)
|
man.*.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur##*.}"
|
||||||
cur="${cur##*.}"
|
__gitcomp "cmd path" "$pfx" "$cur_"
|
||||||
__gitcomp "cmd path" "$pfx" "$cur"
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
mergetool.*.*)
|
mergetool.*.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur##*.}"
|
||||||
cur="${cur##*.}"
|
__gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
|
||||||
__gitcomp "cmd path trustExitCode" "$pfx" "$cur"
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
pager.*)
|
pager.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur#*.}"
|
||||||
cur="${cur#*.}"
|
|
||||||
__git_compute_all_commands
|
__git_compute_all_commands
|
||||||
__gitcomp "$__git_all_commands" "$pfx" "$cur"
|
__gitcomp "$__git_all_commands" "$pfx" "$cur_"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
remote.*.*)
|
remote.*.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur##*.}"
|
||||||
cur="${cur##*.}"
|
|
||||||
__gitcomp "
|
__gitcomp "
|
||||||
url proxy fetch push mirror skipDefaultUpdate
|
url proxy fetch push mirror skipDefaultUpdate
|
||||||
receivepack uploadpack tagopt pushurl
|
receivepack uploadpack tagopt pushurl
|
||||||
" "$pfx" "$cur"
|
" "$pfx" "$cur_"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
remote.*)
|
remote.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur#*.}"
|
||||||
cur="${cur#*.}"
|
__gitcomp "$(__git_remotes)" "$pfx" "$cur_" "."
|
||||||
__gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
url.*.*)
|
url.*.*)
|
||||||
local pfx="${cur%.*}."
|
local pfx="${cur%.*}." cur_="${cur##*.}"
|
||||||
cur="${cur##*.}"
|
__gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
|
||||||
__gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user