From: Thomas Gummerer <t.gummerer@gmail•com>
To: Junio C Hamano <gitster@pobox•com>
Cc: Denton Liu <liu.denton@gmail•com>,
Git Mailing List <git@vger•kernel.org>,
Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail•com>,
Joel Teichroeb <joel@teichroeb•net>,
Johannes Schindelin <Johannes.Schindelin@gmx•de>,
Matthew Kraai <mkraai@its•jnj.com>
Subject: Re: [REGRESSION ps/stash-in-c] git stash show -v
Date: Wed, 20 Mar 2019 21:45:04 +0000 [thread overview]
Message-ID: <20190320214504.GC32487@hank.intra.tgummerer.com> (raw)
In-Reply-To: <xmqqwokuwe9w.fsf@gitster-ct.c.googlers.com>
On 03/20, Junio C Hamano wrote:
> Thomas Gummerer <t.gummerer@gmail•com> writes:
>
> > Subject: [PATCH] stash: setup default diff output format if necessary
> >
> > In the scripted 'git stash show' when no arguments are passed, we just
> > pass '--stat' to 'git diff'. When any argument is passed to 'stash
> > show', we no longer pass '--stat' to 'git diff', and pass whatever
> > flags are passed directly through to 'git diff'.
> >
> > By default 'git diff' shows the patch output. So when we a user uses
> > 'git stash show -v', they would be shown the diff, because that's the
> > default behaviour of 'git diff', but not actually directly triggered
> > by passing the '-v'.
> >
> > In the C version of 'git stash show', we try to emulate that
> > behaviour using the internal diff API. However we forgot to set up
> > the default output format, in case it wasn't set by any of the flags
> > that were passed through.
>
> Well explained. It might have avoided such a bug if the code did
> not manually stuff the diffopt.* structure fields (instead, e.g.
> prepare an array of strings like {"diff", "--stat", NULL} and let
> the option parser diff_opt_parse() to do its job), but that is
> lamenting over water under the bridge.
I actually think this is still a valid point. I'm not too familiar
with the diff API, which is why I missed this during my review in the
first place, but I feel like using 'diff_opt_parse()' is still the
right choice here. Both to fix this bug and to avoid potential
further ones.
Let me give implementing using that a try, I have a feeling like that
might turn out to be better code.
> > So 'git stash show -v' in the builtin
> > version of stash would be completely silent, while it would show the
> > diff before.
>
> That sounds reasonable. Thanks for a quick diagnosis and a fix.
>
> > Fix this by setting up the default output format for 'git diff'.
> >
> > Reported-by: Denton Liu <liu.denton@gmail•com>
> > Signed-off-by: Thomas Gummerer <t.gummerer@gmail•com>
> > ---
> > builtin/stash.c | 4 ++++
> > t/t3903-stash.sh | 18 ++++++++++++++++++
> > 2 files changed, 22 insertions(+)
> >
> > diff --git a/builtin/stash.c b/builtin/stash.c
> > index 51df092633..012662ce68 100644
> > --- a/builtin/stash.c
> > +++ b/builtin/stash.c
> > @@ -761,6 +761,10 @@ static int show_stash(int argc, const char **argv, const char *prefix)
> > free_stash_info(&info);
> > usage_with_options(git_stash_show_usage, options);
> > }
> > + if (!rev.diffopt.output_format) {
> > + rev.diffopt.output_format = DIFF_FORMAT_PATCH;
> > + diff_setup_done(&rev.diffopt);
> > + }
>
> Hmph. Does this result in setup_done() called twice? As it would
> indicate another bug in the original code if setup_done() was never
> called, I am assuming that another setup_done() call in the same
> codeflow is already there.
No, it is not called anywhere, will fix that as well in v2.
> > rev.diffopt.flags.recursive = 1;
> > setup_diff_pager(&rev.diffopt);
> > diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
> > index 97cc71fbaf..e0a50ab267 100755
> > --- a/t/t3903-stash.sh
> > +++ b/t/t3903-stash.sh
> > @@ -612,6 +612,24 @@ test_expect_success 'stash show -p - no stashes on stack, stash-like argument' '
> > test_cmp expected actual
> > '
> >
> > +test_expect_success 'stash show -v shows diff' '
> > + git reset --hard &&
> > + echo foo >>file &&
> > + STASH_ID=$(git stash create) &&
> > + git reset --hard &&
> > + cat >expected <<-EOF &&
> > + diff --git a/file b/file
> > + index 7601807..71b52c4 100644
> > + --- a/file
> > + +++ b/file
> > + @@ -1 +1,2 @@
> > + baz
> > + +foo
> > + EOF
> > + git stash show -v ${STASH_ID} >actual &&
> > + test_cmp expected actual
> > +'
> > +
> > test_expect_success 'drop: fail early if specified stash is not a stash ref' '
> > git stash clear &&
> > test_when_finished "git reset --hard HEAD && git stash clear" &&
next prev parent reply other threads:[~2019-03-20 21:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-19 19:05 [REGRESSION ps/stash-in-c] git stash show -v Denton Liu
2019-03-19 23:18 ` Thomas Gummerer
2019-03-20 1:00 ` Junio C Hamano
2019-03-20 21:45 ` Thomas Gummerer [this message]
2019-03-20 1:04 ` Junio C Hamano
2019-03-20 5:04 ` Jeff King
2019-03-20 9:30 ` Duy Nguyen
2019-03-20 21:59 ` Thomas Gummerer
2019-03-20 22:49 ` [PATCH v2] stash: setup default diff output format if necessary Thomas Gummerer
2019-03-20 23:04 ` Denton Liu
2019-03-20 23:09 ` Denton Liu
2019-03-28 20:45 ` Thomas Gummerer
2019-03-21 9:51 ` Jeff King
2019-03-22 3:25 ` Junio C Hamano
2019-03-22 3:48 ` Jeff King
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=20190320214504.GC32487@hank.intra.tgummerer.com \
--to=t.gummerer@gmail$(echo .)com \
--cc=Johannes.Schindelin@gmx$(echo .)de \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=joel@teichroeb$(echo .)net \
--cc=liu.denton@gmail$(echo .)com \
--cc=mkraai@its$(echo .)jnj.com \
--cc=ungureanupaulsebastian@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox