diff mbox series

[v2,2/3] git-completion.bash: extract from else in _git_stash()

Message ID 430d5acf972f39aa8cfc9b266dd658aabcf1babb.1616574955.git.liu.denton@gmail.com (mailing list archive)
State New, archived
Headers show
Series git-completion.bash: improvements to _git_stash() | expand

Commit Message

Denton Liu March 24, 2021, 8:36 a.m. UTC
To save a level of indentation, perform an early return in the "if" arm
so we can move the "else" code out of the block.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 contrib/completion/git-completion.bash | 73 +++++++++++++-------------
 1 file changed, 37 insertions(+), 36 deletions(-)

Comments

SZEDER Gábor March 28, 2021, 10:30 a.m. UTC | #1
On Wed, Mar 24, 2021 at 01:36:28AM -0700, Denton Liu wrote:
> To save a level of indentation, perform an early return in the "if" arm
> so we can move the "else" code out of the block.
> 
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 73 +++++++++++++-------------
>  1 file changed, 37 insertions(+), 36 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index a2f1b5e916..8d4d8cc0fe 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -3035,44 +3035,45 @@ _git_stash ()

That "if arm" mentioned in the commit message outside the patch
context looks like this:

        if [ -z "$subcommand" ]; then
                case "$cur" in
                [ handle the cases when there is no subcommand]

So we could simplify this further dropping that "if" completely, and
unify the two case blocks from the if and else branches like this:

        case "$subcommand,$cur" in
        [ handle the cases without a subcommand ]
        ,--*)  [ ... ]
        [ ... ]
        [ handle the casese with a subcommand, just like you did in
          this patch ]
        esac

I think this would also make the thid patch a bit simpler.

>  			fi
>  			;;
>  		esac
> -	else
> -		case "$subcommand,$cur" in
> -		push,--*)
> -			__gitcomp "$save_opts --message"
> -			;;
> -		save,--*)
> -			__gitcomp "$save_opts"
> -			;;
> -		apply,--*|pop,--*)
> -			__gitcomp "--index --quiet"
> -			;;
> -		drop,--*)
> -			__gitcomp "--quiet"
> -			;;
> -		list,--*)
> -			__gitcomp "--name-status --oneline --patch-with-stat"
> -			;;
> -		show,--*)
> -			__gitcomp "$__git_diff_common_options"
> -			;;
> -		branch,--*)
> -			;;
> -		branch,*)
> -			if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
> -				__git_complete_refs
> -			else
> -				__gitcomp_nl "$(__git stash list \
> -						| sed -n -e 's/:.*//p')"
> -			fi
> -			;;
> -		show,*|apply,*|drop,*|pop,*)
> +		return
> +	fi
> +
> +	case "$subcommand,$cur" in
> +	push,--*)
> +		__gitcomp "$save_opts --message"
> +		;;
> +	save,--*)
> +		__gitcomp "$save_opts"
> +		;;
> +	apply,--*|pop,--*)
> +		__gitcomp "--index --quiet"
> +		;;
> +	drop,--*)
> +		__gitcomp "--quiet"
> +		;;
> +	list,--*)
> +		__gitcomp "--name-status --oneline --patch-with-stat"
> +		;;
> +	show,--*)
> +		__gitcomp "$__git_diff_common_options"
> +		;;
> +	branch,--*)
> +		;;
> +	branch,*)
> +		if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
> +			__git_complete_refs
> +		else
>  			__gitcomp_nl "$(__git stash list \
>  					| sed -n -e 's/:.*//p')"
> -			;;
> -		*)
> -			;;
> -		esac
> -	fi
> +		fi
> +		;;
> +	show,*|apply,*|drop,*|pop,*)
> +		__gitcomp_nl "$(__git stash list \
> +				| sed -n -e 's/:.*//p')"
> +		;;
> +	*)
> +		;;
> +	esac
>  }
>  
>  _git_submodule ()
> -- 
> 2.31.0.rc2.261.g7f71774620
>
diff mbox series

Patch

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index a2f1b5e916..8d4d8cc0fe 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3035,44 +3035,45 @@  _git_stash ()
 			fi
 			;;
 		esac
-	else
-		case "$subcommand,$cur" in
-		push,--*)
-			__gitcomp "$save_opts --message"
-			;;
-		save,--*)
-			__gitcomp "$save_opts"
-			;;
-		apply,--*|pop,--*)
-			__gitcomp "--index --quiet"
-			;;
-		drop,--*)
-			__gitcomp "--quiet"
-			;;
-		list,--*)
-			__gitcomp "--name-status --oneline --patch-with-stat"
-			;;
-		show,--*)
-			__gitcomp "$__git_diff_common_options"
-			;;
-		branch,--*)
-			;;
-		branch,*)
-			if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
-				__git_complete_refs
-			else
-				__gitcomp_nl "$(__git stash list \
-						| sed -n -e 's/:.*//p')"
-			fi
-			;;
-		show,*|apply,*|drop,*|pop,*)
+		return
+	fi
+
+	case "$subcommand,$cur" in
+	push,--*)
+		__gitcomp "$save_opts --message"
+		;;
+	save,--*)
+		__gitcomp "$save_opts"
+		;;
+	apply,--*|pop,--*)
+		__gitcomp "--index --quiet"
+		;;
+	drop,--*)
+		__gitcomp "--quiet"
+		;;
+	list,--*)
+		__gitcomp "--name-status --oneline --patch-with-stat"
+		;;
+	show,--*)
+		__gitcomp "$__git_diff_common_options"
+		;;
+	branch,--*)
+		;;
+	branch,*)
+		if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
+			__git_complete_refs
+		else
 			__gitcomp_nl "$(__git stash list \
 					| sed -n -e 's/:.*//p')"
-			;;
-		*)
-			;;
-		esac
-	fi
+		fi
+		;;
+	show,*|apply,*|drop,*|pop,*)
+		__gitcomp_nl "$(__git stash list \
+				| sed -n -e 's/:.*//p')"
+		;;
+	*)
+		;;
+	esac
 }
 
 _git_submodule ()