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

Re: [PATCH 4/5] git-completion.bash: consolidate cases in _git_stash()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 20, 2021, 10:44 UTC
Message-ID
<877dkx44ma.fsf@evledraar.gmail.com>
In-Reply-To
<4f8d015d54376af277883f57e8b4cf2c63ed8a03.1618910364.git.liu.denton@gmail.com>
On Tue, Apr 20 2021, Denton Liu wrote:
Show 54 quoted lines
> The $subcommand case statement in _git_stash() is quite repetitive.
> Consolidate the cases together into one catch-all case to reduce the
> repetition.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 21 ++-------------------
>  1 file changed, 2 insertions(+), 19 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 30c9a97616..7bce9a0112 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -3032,21 +3032,6 @@ _git_stash ()
>  	fi
>  
>  	case "$subcommand,$cur" in
> -	push,--*)
> -		__gitcomp_builtin stash_push
> -		;;
> -	save,--*)
> -		__gitcomp_builtin stash_save
> -		;;
> -	pop,--*)
> -		__gitcomp_builtin stash_pop
> -		;;
> -	apply,--*)
> -		__gitcomp_builtin stash_apply
> -		;;
> -	drop,--*)
> -		__gitcomp_builtin stash_drop
> -		;;
>  	list,--*)
>  		# NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
>  		__gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
> @@ -3054,8 +3039,8 @@ _git_stash ()
>  	show,--*)
>  		__gitcomp_builtin stash_show "$__git_diff_common_options"
>  		;;
> -	branch,--*)
> -		__gitcomp_builtin stash_branch
> +	*,--*)
> +		__gitcomp_builtin "stash_$subcommand"
>  		;;
>  	branch,*)
>  		if [ $cword -eq $((__git_cmd_idx+2)) ]; then
> @@ -3069,8 +3054,6 @@ _git_stash ()
>  		__gitcomp_nl "$(__git stash list \
>  				| sed -n -e 's/:.*//p')"
>  		;;
> -	*)
> -		;;
>  	esac
>  }

One might think that this introduces a logic error in "git stash doesnotexist" now dispatching to a non-existing "stash_doesnotexist" or something, bu tI see that earlier (omitted from context) in the function there's an exhaustive lit of push/save/pop etc. which guards against this, is is that correct?

Previous: Denton LiuNext: Denton Liu
Message 9 of 18 in “git-completion.bash: fixes on top of 'dl/complete-stash'”
  1. 0/5 git-completion.bash: fixes on top of 'dl/complete-stash'Denton Liu, Apr 20, 2021
  2. 1/5 git-completion.bash: separate some commands onto their own lineDenton Liu, Apr 20, 2021
  3. 2/5 git-completion.bash: rename to $__git_cmd_idxDenton Liu, Apr 20, 2021
  4. Junio C HamanoApr 20, 2021
  5. SZEDER GáborApr 20, 2021
  6. Junio C HamanoApr 20, 2021
  7. 3/5 git-completion.bash: use $__git_cmd_idx in more placesDenton Liu, Apr 20, 2021
  8. 4/5 git-completion.bash: consolidate cases in _git_stash()Denton Liu, Apr 20, 2021
  9. Ævar Arnfjörð BjarmasonApr 20, 2021
  10. Denton LiuApr 21, 2021
  11. 5/5 git-completion.bash: consolidate no-subcommand case for _git_stash()Denton Liu, Apr 20, 2021
  12. Junio C HamanoApr 20, 2021
  13. Denton LiuApr 21, 2021
  14. 0/4 git-completion.bash: fixes on top of 'dl/complete-stash'Denton Liu, Apr 22, 2021
  15. 1/4 git-completion.bash: separate some commands onto their own lineDenton Liu, Apr 22, 2021
  16. 2/4 git-completion.bash: rename to $__git_cmd_idxDenton Liu, Apr 22, 2021
  17. 4/4 git-completion.bash: consolidate cases in _git_stash()Denton Liu, Apr 22, 2021
  18. 3/4 git-completion.bash: use $__git_cmd_idx in more placesDenton Liu, Apr 22, 2021

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.