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

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 72e5e989b ("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>

Shawn O. Pearce committed Jul 13, 2008 at 02:37 UTC ab02dfe533f55535bdb66e05776a4081020322c6
1 file changed +16 -12
contrib/completion/git-completion.bash
+16 -12
@@ -114,9 +114,20 @@ __git_ps1 ()
114 fi
115 }
116
117 +__gitcomp_1 ()
118 +{
119 + local c IFS=' '$'\t'$'\n'
120 + for c in $1; do
121 + case "$c$2" in
122 + --*=*) printf %s$'\n' "$c$2" ;;
123 + *.) printf %s$'\n' "$c$2" ;;
124 + *) printf %s$'\n' "$c$2 " ;;
125 + esac
126 + done
127 +}
128 +
129 __gitcomp ()
130 {
119 - local all c s=$'\n' IFS=' '$'\t'$'\n'
131 local cur="${COMP_WORDS[COMP_CWORD]}"
132 if [ $# -gt 2 ]; then
133 cur="$3"
@@ -124,21 +135,14 @@ __gitcomp ()
135 case "$cur" in
136 --*=)
137 COMPREPLY=()
127 - return
138 ;;
139 *)
130 - for c in $1; do
131 - case "$c$4" in
132 - --*=*) all="$all$c$4$s" ;;
133 - *.) all="$all$c$4$s" ;;
134 - *) all="$all$c$4 $s" ;;
135 - esac
136 - done
140 + local IFS=$'\n'
141 + COMPREPLY=($(compgen -P "$2" \
142 + -W "$(__gitcomp_1 "$1" "$4")" \
143 + -- "$cur"))
144 ;;
145 esac
139 - IFS=$s
140 - COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
141 - return
146 }
147
148 __git_heads ()