git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: Denton Liu <liu.denton@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v2 2/3] git-completion.bash: extract from else in _git_stash()
Date: Sun, 28 Mar 2021 12:30:57 +0200	[thread overview]
Message-ID: <20210328103057.GE2271@szeder.dev> (raw)
In-Reply-To: <430d5acf972f39aa8cfc9b266dd658aabcf1babb.1616574955.git.liu.denton@gmail.com>

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
> 

  reply	other threads:[~2021-03-28 10:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16  0:54 [PATCH 0/3] git-completion.bash: improvements to _git_stash() Denton Liu
2021-03-16  0:54 ` [PATCH 1/3] git-completion.bash: extract from else in _git_stash() Denton Liu
2021-03-16  0:54 ` [PATCH 2/3] git-completion.bash: fix `git <args>... stash branch` bug Denton Liu
2021-03-16  0:54 ` [PATCH 3/3] git-completion.bash: use __gitcomp_builtin() in _git_stash() Denton Liu
2021-03-18  9:46 ` [RESEND PATCH 0/3] git-completion.bash: improvements to _git_stash() Denton Liu
2021-03-18  9:46   ` [RESEND PATCH 1/3] git-completion.bash: extract from else in _git_stash() Denton Liu
2021-03-18  9:46   ` [RESEND PATCH 2/3] git-completion.bash: fix `git <args>... stash branch` bug Denton Liu
2021-03-18 20:30     ` Junio C Hamano
2021-03-19  8:05       ` Denton Liu
2021-03-19 15:53         ` Junio C Hamano
2021-03-18  9:46   ` [RESEND PATCH 3/3] git-completion.bash: use __gitcomp_builtin() in _git_stash() Denton Liu
2021-03-18 21:58   ` [RESEND PATCH 0/3] git-completion.bash: improvements to _git_stash() Junio C Hamano
2021-03-19  8:09     ` Denton Liu
2021-03-19 15:57       ` Junio C Hamano
2021-03-24  8:36 ` [PATCH v2 " Denton Liu
2021-03-24  8:36   ` [PATCH v2 1/3] git-completion.bash: pass $__git_subcommand_idx from __git_main() Denton Liu
2021-03-27 18:35     ` SZEDER Gábor
2021-03-28 10:31     ` SZEDER Gábor
2021-03-24  8:36   ` [PATCH v2 2/3] git-completion.bash: extract from else in _git_stash() Denton Liu
2021-03-28 10:30     ` SZEDER Gábor [this message]
2021-03-24  8:36   ` [PATCH v2 3/3] git-completion.bash: use __gitcomp_builtin() " Denton Liu
2021-03-28 11:04     ` SZEDER Gábor

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210328103057.GE2271@szeder.dev \
    --to=szeder.dev@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=liu.denton@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).