git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] bash-completion: fix getting strategy list

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 19, 2008, 14:18 UTC
Message-ID
<20080819141832.GA20947@spearce.org>
In-Reply-To
<20080819132803.GA26201@laptop>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
Show 15 quoted lines
>   > __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?

Show 36 quoted lines
> 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.
Previous: Nguyen Thai Ngoc DuyNext: Johannes Sixt
Message 5 of 16 in “[BUG] git completion do sed on binary file”
  1. Nguyen Thai Ngoc DuyAug 19, 2008
  2. bash-completion: fix getting strategy listNguyen Thai Ngoc Duy, Aug 19, 2008
  3. Matthieu MoyAug 19, 2008
  4. Nguyen Thai Ngoc DuyAug 19, 2008
  5. Shawn O. PearceAug 19, 2008
  6. Johannes SixtAug 19, 2008
  7. Johannes SixtAug 19, 2008
  8. Nguyen Thai Ngoc DuyAug 20, 2008
  9. Junio C HamanoAug 20, 2008
  10. Junio C HamanoAug 20, 2008
  11. Miklos VajnaAug 20, 2008
  12. Nguyen Thai Ngoc DuyAug 21, 2008
  13. Mikael MagnussonAug 21, 2008
  14. Junio C HamanoAug 21, 2008
  15. Junio C HamanoAug 21, 2008
  16. Miklos VajnaAug 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.