From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Jonathan Nieder <jrnieder@gmail.com>,
Sam Kuper <sam.kuper@uclmail.net>,
git@vger.kernel.org
Subject: Re: [PATCH 2/2] add--interactive: detect bogus diffFilter output
Date: Mon, 05 Mar 2018 12:53:07 -0800 [thread overview]
Message-ID: <xmqqsh9e8css.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20180303055849.GB15952@sigill.intra.peff.net> (Jeff King's message of "Sat, 3 Mar 2018 00:58:49 -0500")
Jeff King <peff@peff.net> writes:
> It's important that the diff-filter only filter the
> individual lines, and that there remain a one-to-one mapping
> between the input and output lines. Otherwise, things like
> hunk-splitting will behave quite unexpectedly (e.g., you
> think you are splitting at one point, but it has a different
> effect in the text patch we apply).
>
> We can't detect all problematic cases, but we can at least
> catch the obvious case where we don't even have the correct
> number of lines.
Will queue. We could probably also make sure that each of the
corresponding line pair begins with the same '-/ /+' letter, but we
need to draw a line and stop somewhere, and I think the number of
lines is probably a good enough place.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> git-add--interactive.perl | 8 ++++++++
> t/t3701-add-interactive.sh | 8 ++++++++
> 2 files changed, 16 insertions(+)
>
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 964c3a7542..ff02008abe 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -705,6 +705,14 @@ sub parse_diff {
> }
> my (@hunk) = { TEXT => [], DISPLAY => [], TYPE => 'header' };
>
> + if (@colored && @colored != @diff) {
> + print STDERR
> + "fatal: mismatched output from interactive.diffFilter\n",
> + "hint: Your filter must maintain a one-to-one correspondence\n",
> + "hint: between its input and output lines.\n";
> + exit 1;
> + }
> +
> for (my $i = 0; $i < @diff; $i++) {
> if ($diff[$i] =~ /^@@ /) {
> push @hunk, { TEXT => [], DISPLAY => [],
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index 64fe56c3d5..9bb17f91b2 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -404,6 +404,14 @@ test_expect_success TTY 'diffFilter filters diff' '
> grep foo:.*content output
> '
>
> +test_expect_success TTY 'detect bogus diffFilter output' '
> + git reset --hard &&
> +
> + echo content >test &&
> + test_config interactive.diffFilter "echo too-short" &&
> + printf y | test_must_fail test_terminal git add -p
> +'
> +
> test_expect_success 'patch-mode via -i prompts for files' '
> git reset --hard &&
next prev parent reply other threads:[~2018-03-05 20:53 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-02 1:19 Bug report: "Use of uninitialized value $_ in print" Sam Kuper
2018-03-02 7:04 ` Jonathan Nieder
2018-03-02 10:46 ` Jeff King
2018-03-02 16:53 ` Junio C Hamano
2018-03-02 16:55 ` Jeff King
2018-03-02 17:15 ` Junio C Hamano
2018-03-03 5:57 ` Jeff King
2018-03-03 5:58 ` [PATCH 1/2] t3701: add a test for interactive.diffFilter Jeff King
2018-03-03 5:58 ` [PATCH 2/2] add--interactive: detect bogus diffFilter output Jeff King
2018-03-05 20:53 ` Junio C Hamano [this message]
2018-03-05 20:56 ` Jeff King
2018-03-05 21:33 ` Ævar Arnfjörð Bjarmason
2018-03-05 22:09 ` Junio C Hamano
2018-03-05 22:15 ` Ævar Arnfjörð Bjarmason
2018-03-05 21:54 ` Bug report: "Use of uninitialized value $_ in print" Jonathan Nieder
2018-03-02 17:28 ` Sam Kuper
2018-03-02 10:42 ` Jeff King
2018-03-02 17:30 ` Sam Kuper
2018-03-03 6:02 ` Jeff King
2018-03-02 17:48 ` Junio C Hamano
2018-03-02 20:34 ` Sam Kuper
2018-03-02 21:53 ` Junio C Hamano
2018-03-03 6:18 ` 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
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=xmqqsh9e8css.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
--cc=sam.kuper@uclmail.net \
/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).