From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: "Martin Storsjö" <martin@martin.st>,
git@vger.kernel.org, "Phillip Wood" <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH] diff --no-index: fix -R with stdin
Date: Mon, 11 Sep 2023 12:04:39 -0700 [thread overview]
Message-ID: <xmqqil8gv8e0.fsf@gitster.g> (raw)
In-Reply-To: <22fdfa3b-f90e-afcc-667c-705fb7670245@web.de> ("René Scharfe"'s message of "Sun, 10 Sep 2023 00:12:52 +0200")
René Scharfe <l.s.r@web.de> writes:
> When -R is given, queue_diff() swaps the mode and name variables of the
> two files to produce a reverse diff. 1e3f26542a (diff --no-index:
> support reading from named pipes, 2023-07-05) added variables that
> indicate whether files are special, i.e named pipes or - for stdin.
> These new variables were not swapped, though, which broke the handling
> of stdin with with -R. Swap them like the other metadata variables.
>
> Reported-by: Martin Storsjö <martin@martin.st>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> Great bug report, thank you!
Looking good. I wish all our bugs are this easy and obvious ;-)
> diff-no-index.c | 1 +
> t/t4053-diff-no-index.sh | 19 +++++++++++++++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/diff-no-index.c b/diff-no-index.c
> index 8aead3e332..e7041b89e3 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -232,6 +232,7 @@ static int queue_diff(struct diff_options *o,
> if (o->flags.reverse_diff) {
> SWAP(mode1, mode2);
> SWAP(name1, name2);
> + SWAP(special1, special2);
> }
>
> d1 = noindex_filespec(name1, mode1, special1);
> diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
> index 6781cc9078..5f059f65fc 100755
> --- a/t/t4053-diff-no-index.sh
> +++ b/t/t4053-diff-no-index.sh
> @@ -224,6 +224,25 @@ test_expect_success "diff --no-index treats '-' as stdin" '
> test_must_be_empty actual
> '
>
> +test_expect_success "diff --no-index -R treats '-' as stdin" '
> + cat >expect <<-EOF &&
> + diff --git b/a/1 a/-
> + index $(git hash-object --stdin <a/1)..$ZERO_OID 100644
> + --- b/a/1
> + +++ a/-
> + @@ -1 +1 @@
> + -1
> + +x
> + EOF
> +
> + test_write_lines x | test_expect_code 1 \
> + git -c core.abbrev=no diff --no-index -R -- - a/1 >actual &&
> + test_cmp expect actual &&
> +
> + test_write_lines 1 | git diff --no-index -R -- a/1 - >actual &&
> + test_must_be_empty actual
> +'
> +
> test_expect_success 'diff --no-index refuses to diff stdin and a directory' '
> test_must_fail git diff --no-index -- - a </dev/null 2>err &&
> grep "fatal: cannot compare stdin to a directory" err
> --
> 2.42.0
next prev parent reply other threads:[~2023-09-11 21:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-09 20:42 Regression in git diff with stdin, with -R Martin Storsjö
2023-09-09 22:12 ` [PATCH] diff --no-index: fix -R with stdin René Scharfe
2023-09-10 10:00 ` Phillip Wood
2023-09-10 18:41 ` Taylor Blau
2023-09-11 19:04 ` Junio C Hamano [this message]
2023-09-11 19:20 ` Martin Storsjö
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=xmqqil8gv8e0.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=martin@martin.st \
--cc=phillip.wood@dunelm.org.uk \
/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 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 NNTP newsgroup(s).