public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce•org>
To: Nguyen Thai Ngoc Duy <pclouds@gmail•com>
Cc: Git Mailing List <git@vger•kernel.org>
Subject: Re: [PATCH] bash-completion: fix getting strategy list
Date: Tue, 19 Aug 2008 07:18:32 -0700	[thread overview]
Message-ID: <20080819141832.GA20947@spearce.org> (raw)
In-Reply-To: <20080819132803.GA26201@laptop>

Nguyen Thai Ngoc Duy <pclouds@gmail•com> wrote:
>   > __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.

Youch.
 
>   Maybe something like this?

Yea, this looks reasonable.  ACK from me, though the bigger change
is to builtin-merge and not the completion. Miklos?  Dscho?

> 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)"

-- 
Shawn.

  parent reply	other threads:[~2008-08-19 14:19 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 ` [PATCH] bash-completion: fix getting strategy list Nguyen Thai Ngoc Duy
2008-08-19 13:35   ` Matthieu Moy
2008-08-19 13:46     ` Nguyen Thai Ngoc Duy
2008-08-19 14:18   ` Shawn O. Pearce [this message]
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=20080819141832.GA20947@spearce.org \
    --to=spearce@spearce$(echo .)org \
    --cc=git@vger$(echo .)kernel.org \
    --cc=pclouds@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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