diff mbox series

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

Message ID 4f8d015d54376af277883f57e8b4cf2c63ed8a03.1618910364.git.liu.denton@gmail.com (mailing list archive)
State Superseded
Headers show
Series git-completion.bash: fixes on top of 'dl/complete-stash' | expand

Commit Message

Denton Liu April 20, 2021, 9:19 a.m. UTC
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(-)

Comments

Ævar Arnfjörð Bjarmason April 20, 2021, 10:44 a.m. UTC | #1
On Tue, Apr 20 2021, Denton Liu wrote:

> 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?
Denton Liu April 21, 2021, 4:03 a.m. UTC | #2
Hi Ævar,

On Tue, Apr 20, 2021 at 12:44:45PM +0200, Ævar Arnfjörð Bjarmason wrote:
> 
> On Tue, Apr 20 2021, Denton Liu wrote:
> 
> > 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?

Yep, that's exactly correct.
diff mbox series

Patch

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
 }