Cache the list of merge strategies and available commands during load.
Since the user's git installation is not likely to grow a new command or merge strategy in the lifespan of the current shell process we can save time during completion operations by caching these lists during sourcing of the completion support. If the git executable is not available or we run into errors while caching at load time then we defer these to runtime and generate the list on the fly. This might happen if the user doesn't put git into their PATH until after the completion script gets sourced. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Nov 27, 2006 at 15:11 UTC
b51ec6bddb572def384a21a18d5919a488e06ffb
1 file changed
+19
-1
contrib/completion/git-completion.bash
+19
-1
@@ -18,7 +18,13 @@
18
# 2) Added the following line to your .bashrc:
19
# source ~/.git-completion.sh
20
#
21
-# 3) Consider changing your PS1 to also show the current branch:
21
+# 3) You may want to make sure the git executable is available
22
+# in your PATH before this script is sourced, as some caching
23
+# is performed while the script loads. If git isn't found
24
+# at source time then all lookups will be done on demand,
25
+# which may be slightly slower.
26
+#
27
+# 4) Consider changing your PS1 to also show the current branch:
28
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
29
#
30
# The argument to __git_ps1 will be displayed only if you
@@ -150,6 +156,10 @@ __git_remotes ()
156
157
__git_merge_strategies ()
158
{
159
+ if [ -n "$__git_merge_strategylist" ]; then
160
+ echo "$__git_merge_strategylist"
161
+ return
162
+ fi
163
sed -n "/^all_strategies='/{
164
s/^all_strategies='//
165
s/'//
@@ -157,6 +167,8 @@ __git_merge_strategies ()
167
q
168
}" "$(git --exec-path)/git-merge"
169
}
170
+__git_merge_strategylist=
171
+__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
172
173
__git_complete_file ()
174
{
@@ -214,6 +226,10 @@ __git_complete_revlist ()
226
227
__git_commands ()
228
{
229
+ if [ -n "$__git_commandlist" ]; then
230
+ echo "$__git_commandlist"
231
+ return
232
+ fi
233
local i IFS=" "$'\n'
234
for i in $(git help -a|egrep '^ ')
235
do
@@ -263,6 +279,8 @@ __git_commands ()
279
esac
280
done
281
}
282
+__git_commandlist=
283
+__git_commandlist="$(__git_commands 2>/dev/null)"
284
285
__git_aliases ()
286
{