git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Nikita Bobko <nikitabobko@gmail.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>, git@vger.kernel.org
Subject: Re: [Bug report] diff.noprefix config is ignored for interactive `add`
Date: Tue, 6 Apr 2021 17:36:58 -0400	[thread overview]
Message-ID: <YGzUerPL7V8jDxHo@coredump.intra.peff.net> (raw)
In-Reply-To: <CAMJzOtyzu8y5mWdKXe3MPe8ZoJs8O=me8Xuu0t77YVdAMc7Tgg@mail.gmail.com>

On Tue, Apr 06, 2021 at 12:15:28PM +0200, Nikita Bobko wrote:

> Steps to reproduce:
> 1. Run `git -c diff.noprefix=true add -p`
> 
> Expected behavior:
> `a/` and `b/` prefixes are not shown during interactive `add`
> like this:
> [...]
> Actual behavior:
> `a/` and `b/` prefixes are shown instead. Like this:

That's not too surprising. The add-interactive script is built around
the diff-tree plumbing command, which does not respect a lot of
"cosmetic" config, especially if it would make the diff hard to parse.
So the add-interactive command would have to manually plumb through the
config option, like we do for some other options.

In this case, I think you'd want to enable the option only for the
version of the diff we show to the user (since the machine-readable one
has to actually be parsed by git-apply). This is what we do for
supporting color diffs, for example.

I imagine something like this:

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index bc3a1e8eff..1a249e15cb 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -43,6 +43,12 @@
 		$repo->get_color('color.diff.new', 'green'),
 	) : ();
 
+# options to feed to diff to produce human-readable version
+my @human_diff_opts = (
+	$diff_use_color ? '--color' : (),
+	$repo->config_bool('diff.noprefix') ? qw(--no-prefix) : (),
+);
+
 my $normal_color = $repo->get_color("", "reset");
 
 my $diff_algorithm = $repo->config('diff.algorithm');
@@ -714,8 +720,8 @@ sub parse_diff {
 	}
 	my @diff = run_cmd_pipe("git", @diff_cmd, qw(--no-color --), $path);
 	my @colored = ();
-	if ($diff_use_color) {
-		my @display_cmd = ("git", @diff_cmd, qw(--color --), $path);
+	if (@human_diff_opts) {
+		my @display_cmd = ("git", @diff_cmd, @human_diff_opts, '--', $path);
 		if (defined $diff_filter) {
 			# quotemeta is overkill, but sufficient for shell-quoting
 			my $diff = join(' ', map { quotemeta } @display_cmd);

would work, but I didn't really test it. There's another hitch, which is
that this subsystem has all been re-written in C. So we'd really want to
implement it in the new code (possibly in both places, though maybe it
is time to consider cutting over from the perl script to the C one by
deafult?).

But hopefully this illustrates the general idea, and gives somebody
interested in the feature enough to work up their own patch.

-Peff

  reply	other threads:[~2021-04-06 21:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 10:15 [Bug report] diff.noprefix config is ignored for interactive `add` Nikita Bobko
2021-04-06 21:36 ` Jeff King [this message]
2021-04-06 21:57   ` Junio C Hamano
2021-04-06 22:47     ` 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=YGzUerPL7V8jDxHo@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=nikitabobko@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).