From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] bash-completion: fix getting strategy list
Date: Tue, 19 Aug 2008 20:28:03 +0700 [thread overview]
Message-ID: <20080819132803.GA26201@laptop> (raw)
In-Reply-To: <fcaeb9bf0808190527q60869fd0uccbfd165431a752d@mail.gmail.com>
Bash completion needs to know what strategies git supports. Maybe
other similar tools have the same demand. So add
"git merge--show-strategies"
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
On Tue, Aug 19, 2008 at 07:27:39PM +0700, Nguyen Thai Ngoc Duy wrote:
> Probably missed since git-merge builtin effort:
>
> __git_merge_strategies ()
> {
> if [ -n "$__git_merge_strategylist" ]; then
> echo "$__git_merge_strategylist"
> return
> fi
> sed -n "/^all_strategies='/{
> s/^all_strategies='//
> s/'//
> p
> q
> }" "$(git --exec-path)/git-merge"
> }
>
> It takes several seconds to finish that function.
Maybe something like this?
Documentation/git-merge.txt | 4 ++++
builtin-merge.c | 7 +++++++
contrib/completion/git-completion.bash | 7 +------
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 17a15ac..f3fe1c9 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -12,6 +12,7 @@ SYNOPSIS
'git merge' [-n] [--stat] [--no-commit] [--squash] [-s <strategy>]...
[-m <msg>] <remote> <remote>...
'git merge' <msg> HEAD <remote>...
+'git merge' --show-strategies
DESCRIPTION
-----------
@@ -37,6 +38,9 @@ include::merge-options.txt[]
least one <remote>. Specifying more than one <remote>
obviously means you are trying an Octopus.
+--show-strategies::
+ Show all available strategies. For internal use only.
+
include::merge-strategies.txt[]
diff --git a/builtin-merge.c b/builtin-merge.c
index de025ac..613c96a 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -802,6 +802,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
const char *best_strategy = NULL, *wt_strategy = NULL;
struct commit_list **remotes = &remoteheads;
+ /* needed for git bash completion and similar tools */
+ if (argc == 2 && !strcmp(argv[1], "--show-strategies")) {
+ for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
+ printf("%s\n", all_strategy[i].name);
+ return 0;
+ }
+
setup_work_tree();
if (unmerged_cache())
die("You are in the middle of a conflicted merge.");
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 158b912..1eea49a 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -271,12 +271,7 @@ __git_merge_strategies ()
echo "$__git_merge_strategylist"
return
fi
- sed -n "/^all_strategies='/{
- s/^all_strategies='//
- s/'//
- p
- q
- }" "$(git --exec-path)/git-merge"
+ $(git --exec-path)/git-merge --show-strategies
}
__git_merge_strategylist=
__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
--
1.6.0.96.g2fad1.dirty
next prev parent reply other threads:[~2008-08-19 13:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-19 12:27 [BUG] git completion do sed on binary file Nguyen Thai Ngoc Duy
2008-08-19 13:28 ` Nguyen Thai Ngoc Duy [this message]
2008-08-19 13:35 ` [PATCH] bash-completion: fix getting strategy list Matthieu Moy
2008-08-19 13:46 ` Nguyen Thai Ngoc Duy
2008-08-19 14:18 ` Shawn O. Pearce
2008-08-19 14:50 ` Johannes Sixt
2008-08-19 14:57 ` Johannes Sixt
2008-08-20 16:58 ` Nguyen Thai Ngoc Duy
2008-08-20 18:22 ` Junio C Hamano
2008-08-20 21:13 ` Junio C Hamano
2008-08-20 22:39 ` Miklos Vajna
2008-08-21 0:43 ` Nguyen Thai Ngoc Duy
2008-08-21 2:14 ` Mikael Magnusson
2008-08-21 4:45 ` Junio C Hamano
2008-08-21 5:07 ` Junio C Hamano
2008-08-21 14:06 ` Miklos Vajna
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=20080819132803.GA26201@laptop \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.