All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Git Mailing List" <git@vger.kernel.org>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: Re: [PATCH 5/5] git-completion.bash: consolidate no-subcommand case for _git_stash()
Date: Tue, 20 Apr 2021 21:08:17 -0700	[thread overview]
Message-ID: <YH+lMZCg5cqniPaU@generichostname> (raw)
In-Reply-To: <xmqqk0ow4q7k.fsf@gitster.g>

Hi Junio,

On Tue, Apr 20, 2021 at 02:10:39PM -0700, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > We have a separate if case for when no subcommand is given. It is
> > simpler to just consolidate this logic into the case statement below.
> 
> Hmph, I am not quite sure if the removal of the first case is making
> the code easier to follow.  Is this supposed to be a no-op clean-up,
> or is it fixing some bugs?

This is simply a no-op clean-up. I am on the fence about doing this
change as well so I can drop it on the next reroll unless someone has
objections.

> > It would be nice to complete remove the magic that deals with indices
> > and replace it with what was originally there,
> >
> > 	if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then
> > 	        subcommand="push"
> > 	fi
> >
> > but this gives a slightly incorrect completion. In the case where we're
> > attempting to complete `git stash -a <TAB>` we will get the subcommands
> > back as a respose instead of the completions for `git stash push`, which
> > is what we'd expect. We could potentially hardcode all of the short
> > options but that would be too much work to maintain so we stick with the
> > index solution.
> >
> > Signed-off-by: Denton Liu <liu.denton@gmail.com>
> > ---
> >  contrib/completion/git-completion.bash | 30 +++++++++++++-------------
> >  1 file changed, 15 insertions(+), 15 deletions(-)
> >
> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> > index 7bce9a0112..060adc0ed7 100644
> > --- a/contrib/completion/git-completion.bash
> > +++ b/contrib/completion/git-completion.bash
> > @@ -3016,22 +3016,22 @@ _git_stash ()
> >  	local subcommands='push list show apply clear drop pop create branch'
> >  	local subcommand="$(__git_find_on_cmdline "$subcommands save")"
> >  
> > -	if [ -z "$subcommand" ]; then
> > -		case "$((cword - __git_cmd_idx)),$cur" in
> > -		*,--*)
> > -			__gitcomp_builtin stash_push
> > -			;;
> > -		1,sa*)
> > -			__gitcomp "save"
> > -			;;
> > -		1,*)
> > -			__gitcomp "$subcommands"
> > -			;;
> > -		esac
> > -		return
> > -	fi
> > -
> >  	case "$subcommand,$cur" in
> > +	,--*)
> > +		__gitcomp_builtin stash_save
> > +		;;
> > +	,sa*)
> > +		__git_init_builtin_opts stash_save

Also, I just noticed upon re-reading this patch that this is some
leftover cruft. But moot point since I'll be dropping this patch.

> > +		if ((cword - __git_cmd_idx == 1)); then
> > +			__gitcomp "save"
> > +		fi
> > +		;;
> > +	,*)
> > +		__git_init_builtin_opts stash_save
> > +		if ((cword - __git_cmd_idx == 1)); then
> > +			__gitcomp "$subcommands"
> > +		fi
> > +		;;
> >  	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"

  reply	other threads:[~2021-04-21  4:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-20  9:19 [PATCH 0/5] git-completion.bash: fixes on top of 'dl/complete-stash' Denton Liu
2021-04-20  9:19 ` [PATCH 1/5] git-completion.bash: separate some commands onto their own line Denton Liu
2021-04-20  9:19 ` [PATCH 2/5] git-completion.bash: rename to $__git_cmd_idx Denton Liu
2021-04-20 20:50   ` Junio C Hamano
2021-04-20 21:14     ` SZEDER Gábor
2021-04-20 22:31       ` Junio C Hamano
2021-04-20  9:19 ` [PATCH 3/5] git-completion.bash: use $__git_cmd_idx in more places Denton Liu
2021-04-20  9:19 ` [PATCH 4/5] git-completion.bash: consolidate cases in _git_stash() Denton Liu
2021-04-20 10:44   ` Ævar Arnfjörð Bjarmason
2021-04-21  4:03     ` Denton Liu
2021-04-20  9:19 ` [PATCH 5/5] git-completion.bash: consolidate no-subcommand case for _git_stash() Denton Liu
2021-04-20 21:10   ` Junio C Hamano
2021-04-21  4:08     ` Denton Liu [this message]
2021-04-22 10:00 ` [PATCH v2 0/4] git-completion.bash: fixes on top of 'dl/complete-stash' Denton Liu
2021-04-22 10:00   ` [PATCH v2 1/4] git-completion.bash: separate some commands onto their own line Denton Liu
2021-04-22 10:00   ` [PATCH v2 2/4] git-completion.bash: rename to $__git_cmd_idx Denton Liu
2021-04-22 10:00   ` [PATCH v2 3/4] git-completion.bash: use $__git_cmd_idx in more places Denton Liu
2021-04-22 10:00   ` [PATCH v2 4/4] git-completion.bash: consolidate cases in _git_stash() Denton Liu

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

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

  git send-email \
    --in-reply-to=YH+lMZCg5cqniPaU@generichostname \
    --to=liu.denton@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=szeder.dev@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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.