From: Stephen Boyd <bebarino@gmail.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org, Clemens Buchacher <drizzd@aon.at>,
Sverre Rabbelier <srabbelier@gmail.com>
Subject: Re: [PATCH/RFC 2/2] completion: allow use without compiling
Date: Tue, 27 Oct 2009 18:43:21 -0700 [thread overview]
Message-ID: <4AE7A1B9.5010001@gmail.com> (raw)
In-Reply-To: <20091027185223.GH10505@spearce.org>
Shawn O. Pearce wrote:
> NAK on code duplication, especially this much. As Junio already
> pointed out in this thread we need an approach that doesn't cause
> this sort of redundant code.
Ok. Following Junio's suggestion I think we would have to do the following:
(1) Revert the rename (git-completion.bash.in -> git-completion.bash)
(2) Add a "generation" mode to git-completion.bash.generate to generate
the lists and output them to a file
(3) Add logic in git-completion.bash.generate to source the generated
file if it exists
(4) Source git-completion.bash.generate in git-completion.bash to get
the functions moved there
In the end we would have git-completion.bash sourcing
git-completion.bash.generate which then sources the generated file. I
assume this is slower than compiling to just one file.
Or we could just not load the caches until they're needed. This just
delays the performance hit to completion time, but at least it speeds up
loading the script without the need to compile and still has the benefit
of some caching. It also allows users to keep the completion of their
custom merge strategies and git programs in their PATH.
----8<----
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index d3fec32..8a7cde3 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -326,10 +326,15 @@ __git_remotes ()
__git_merge_strategies ()
{
- if [ -n "${__git_merge_strategylist-}" ]; then
+ if [ -n "${__git_merge_strategylist-}" ] || {
+ __git_merge_strategylist=$(__git_merge_strategies_gen 2>/dev/null)
+ }; then
echo "$__git_merge_strategylist"
- return
fi
+}
+
+__git_merge_strategies_gen ()
+{
git merge -s help 2>&1 |
sed -n -e '/[Aa]vailable strategies are: /,/^$/{
s/\.$//
@@ -340,7 +345,6 @@ __git_merge_strategies ()
}'
}
__git_merge_strategylist=
-__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
__git_complete_file ()
{
@@ -491,10 +495,15 @@ __git_complete_strategy ()
__git_all_commands ()
{
- if [ -n "${__git_all_commandlist-}" ]; then
+ if [ -n "${__git_all_commandlist-}" ] || {
+ __git_all_commandlist="$(__git_all_commands_gen 2>/dev/null)"
+ }; then
echo "$__git_all_commandlist"
- return
fi
+}
+
+__git_all_commands_gen ()
+{
local i IFS=" "$'\n'
for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
do
@@ -505,14 +514,18 @@ __git_all_commands ()
done
}
__git_all_commandlist=
-__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
__git_porcelain_commands ()
{
- if [ -n "${__git_porcelain_commandlist-}" ]; then
+ if [ -n "${__git_porcelain_commandlist-}" ] || {
+ __git_porcelain_commandlist="$(__git_porcelain_commands_gen 2>/dev/null)"
+ }; then
echo "$__git_porcelain_commandlist"
- return
fi
+}
+
+__git_porcelain_commands_gen ()
+{
local i IFS=" "$'\n'
for i in "help" $(__git_all_commands)
do
@@ -596,7 +609,6 @@ __git_porcelain_commands ()
done
}
__git_porcelain_commandlist=
-__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
__git_aliases ()
{
next prev parent reply other threads:[~2009-10-28 1:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-26 20:31 [PATCH 0/2] pre-generated completion fix and RFC Stephen Boyd
2009-10-26 20:31 ` [PATCH 1/2] completion: ignore custom merge strategies when pre-generating Stephen Boyd
2009-10-26 20:31 ` [PATCH/RFC 2/2] completion: allow use without compiling Stephen Boyd
2009-10-26 23:59 ` Junio C Hamano
2009-10-27 0:33 ` Clemens Buchacher
2009-10-27 0:38 ` Junio C Hamano
2009-10-28 8:19 ` Clemens Buchacher
2009-10-27 2:49 ` Stephen Boyd
2009-10-27 18:52 ` Shawn O. Pearce
2009-10-28 1:43 ` Stephen Boyd [this message]
2009-10-28 7:18 ` Junio C Hamano
2009-10-28 7:29 ` Stephen Boyd
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=4AE7A1B9.5010001@gmail.com \
--to=bebarino@gmail.com \
--cc=drizzd@aon.at \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=spearce@spearce.org \
--cc=srabbelier@gmail.com \
/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).