提交 ab02dfe5 编写于 作者: S Shawn O. Pearce 提交者: Junio C Hamano

bash completion: Improve responsiveness of git-log completion

Junio noticed the bash completion has been taking a long time lately.
Petr Baudis tracked it down to 72e5e989 ("bash: Add space after
unique command name is completed.").  Tracing the code showed
we spent significant time inside of this loop within __gitcomp,
due to the string copying overhead.

  [28.146109654] _git common over
  [28.164791148] gitrefs in
  [28.280302268] gitrefs dir out
  [28.300939737] gitcomp in
  [28.308378112] gitcomp pre-case
* [28.313407453] gitcomp iter in
* [28.701270296] gitcomp iter out
  [28.713370786] out normal

Since __git_refs avoids this string copying by forking and using
echo we use the same trick here when we need to finish generating
the names for the caller.
Signed-off-by: NShawn O. Pearce <spearce@spearce.org>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 e09c4e75
...@@ -114,9 +114,20 @@ __git_ps1 () ...@@ -114,9 +114,20 @@ __git_ps1 ()
fi fi
} }
__gitcomp_1 ()
{
local c IFS=' '$'\t'$'\n'
for c in $1; do
case "$c$2" in
--*=*) printf %s$'\n' "$c$2" ;;
*.) printf %s$'\n' "$c$2" ;;
*) printf %s$'\n' "$c$2 " ;;
esac
done
}
__gitcomp () __gitcomp ()
{ {
local all c s=$'\n' IFS=' '$'\t'$'\n'
local cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
if [ $# -gt 2 ]; then if [ $# -gt 2 ]; then
cur="$3" cur="$3"
...@@ -124,21 +135,14 @@ __gitcomp () ...@@ -124,21 +135,14 @@ __gitcomp ()
case "$cur" in case "$cur" in
--*=) --*=)
COMPREPLY=() COMPREPLY=()
return
;; ;;
*) *)
for c in $1; do local IFS=$'\n'
case "$c$4" in COMPREPLY=($(compgen -P "$2" \
--*=*) all="$all$c$4$s" ;; -W "$(__gitcomp_1 "$1" "$4")" \
*.) all="$all$c$4$s" ;; -- "$cur"))
*) all="$all$c$4 $s" ;;
esac
done
;; ;;
esac esac
IFS=$s
COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
return
} }
__git_heads () __git_heads ()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册