Skip to content

Commit

Permalink
bash completion: Improve responsiveness of git-log completion
Browse files Browse the repository at this point in the history
Junio noticed the bash completion has been taking a long time lately.
Petr Baudis tracked it down to 72e5e98 ("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: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Jul 13, 2008
1 parent e09c4e7 commit ab02dfe
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,35 @@ __git_ps1 ()
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 ()
{
local all c s=$'\n' IFS=' '$'\t'$'\n'
local cur="${COMP_WORDS[COMP_CWORD]}"
if [ $# -gt 2 ]; then
cur="$3"
fi
case "$cur" in
--*=)
COMPREPLY=()
return
;;
*)
for c in $1; do
case "$c$4" in
--*=*) all="$all$c$4$s" ;;
*.) all="$all$c$4$s" ;;
*) all="$all$c$4 $s" ;;
esac
done
local IFS=$'\n'
COMPREPLY=($(compgen -P "$2" \
-W "$(__gitcomp_1 "$1" "$4")" \
-- "$cur"))
;;
esac
IFS=$s
COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
return
}

__git_heads ()
Expand Down

0 comments on commit ab02dfe

Please sign in to comment.