From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 3/4] Cache the list of merge strategies and available commands during load.
Date: Mon, 27 Nov 2006 15:11:52 -0500 [thread overview]
Message-ID: <20061127201152.GC7308@spearce.org> (raw)
In-Reply-To: <139669072795537547ec26b69115509100dcd7ec.1164658223.git.spearce@spearce.org>
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>
---
This is by request of Junio. :-)
contrib/completion/git-completion.bash | 20 +++++++++++++++++++-
1 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index d4eb138..ba3adb6 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -18,7 +18,13 @@
# 2) Added the following line to your .bashrc:
# source ~/.git-completion.sh
#
-# 3) Consider changing your PS1 to also show the current branch:
+# 3) You may want to make sure the git executable is available
+# in your PATH before this script is sourced, as some caching
+# is performed while the script loads. If git isn't found
+# at source time then all lookups will be done on demand,
+# which may be slightly slower.
+#
+# 4) Consider changing your PS1 to also show the current branch:
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#
# The argument to __git_ps1 will be displayed only if you
@@ -150,6 +156,10 @@ __git_remotes ()
__git_merge_strategies ()
{
+ if [ -n "$__git_merge_strategylist" ]; then
+ echo "$__git_merge_strategylist"
+ return
+ fi
sed -n "/^all_strategies='/{
s/^all_strategies='//
s/'//
@@ -157,6 +167,8 @@ __git_merge_strategies ()
q
}" "$(git --exec-path)/git-merge"
}
+__git_merge_strategylist=
+__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
__git_complete_file ()
{
@@ -214,6 +226,10 @@ __git_complete_revlist ()
__git_commands ()
{
+ if [ -n "$__git_commandlist" ]; then
+ echo "$__git_commandlist"
+ return
+ fi
local i IFS=" "$'\n'
for i in $(git help -a|egrep '^ ')
do
@@ -263,6 +279,8 @@ __git_commands ()
esac
done
}
+__git_commandlist=
+__git_commandlist="$(__git_commands 2>/dev/null)"
__git_aliases ()
{
--
1.4.4.1.ge3fb
next prev parent reply other threads:[~2006-11-27 20:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <139669072795537547ec26b69115509100dcd7ec.1164658223.git.spearce@spearce.org>
2006-11-27 20:11 ` [PATCH 2/4] Teach bash about git-commit's options Shawn O. Pearce
2006-11-27 20:11 ` Shawn O. Pearce [this message]
2006-11-27 20:12 ` [PATCH 4/4] Teach bash about git-am/git-apply and their whitespace options Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061127201152.GC7308@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).