git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [Bug report] diff.noprefix config is ignored for interactive `add`
@ 2021-04-06 10:15 Nikita Bobko
  2021-04-06 21:36 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Nikita Bobko @ 2021-04-06 10:15 UTC (permalink / raw)
  To: git

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:
```
diff --git foo foo
index 257cc56..1715acd 100644
--- foo
+++ foo
@@ -1 +1 @@
-foo
+bar
(1/1) Stage this hunk [y,n,q,a,d,e,?]?
```

Actual behavior:
`a/` and `b/` prefixes are shown instead. Like this:
```
diff --git a/foo b/foo
index 257cc56..1715acd 100644
--- a/foo
+++ b/foo
@@ -1 +1 @@
-foo
+bar
(1/1) Stage this hunk [y,n,q,a,d,e,?]?
```

[System Info]
git version:
git version 2.30.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.4.98-1-lts #1 SMP Sat, 13 Feb 2021 19:22:14 +0000 x86_64
compiler info: gnuc: 10.2
libc info: glibc: 2.33
$SHELL (typically, interactive shell): /bin/zsh

[Enabled Hooks]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug report] diff.noprefix config is ignored for interactive `add`
  2021-04-06 10:15 [Bug report] diff.noprefix config is ignored for interactive `add` Nikita Bobko
@ 2021-04-06 21:36 ` Jeff King
  2021-04-06 21:57   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2021-04-06 21:36 UTC (permalink / raw)
  To: Nikita Bobko; +Cc: Johannes Schindelin, git

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug report] diff.noprefix config is ignored for interactive `add`
  2021-04-06 21:36 ` Jeff King
@ 2021-04-06 21:57   ` Junio C Hamano
  2021-04-06 22:47     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2021-04-06 21:57 UTC (permalink / raw)
  To: Jeff King; +Cc: Nikita Bobko, Johannes Schindelin, git

Jeff King <peff@peff.net> writes:

> I imagine something like this:
> ...
> 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.

These "cosmetic appearance" configuration that would affect the
output from diff shown to the user would not be limited to just the
.noprefix, though.  Depending on the users, they would care just as
deeply about any of these:

	.context
	.interHunkContext
	.mnemonicPrefix
        .noprefix
	.relative
	.orderFile

as Nikita does for .noprefix to send a bug report.

Luckily or unluckily, .suppressBlankEmpty and the per-filetype
.xfuncname patterns do impact the output from the plumbing, because
git_diff_basic_config() does read them, even though they are merely
"cosmetic" configurations.

I am unsure how much we should cater to end-user controlled
configuration when we are generating diff output for our own
consumption, but if we were to tweak "add -p" and friends to
pay attention to .noprefix, we probably should do the same for
all the others.

Thanks.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug report] diff.noprefix config is ignored for interactive `add`
  2021-04-06 21:57   ` Junio C Hamano
@ 2021-04-06 22:47     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2021-04-06 22:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Nikita Bobko, Johannes Schindelin, git

On Tue, Apr 06, 2021 at 02:57:46PM -0700, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > I imagine something like this:
> > ...
> > 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.
> 
> These "cosmetic appearance" configuration that would affect the
> output from diff shown to the user would not be limited to just the
> .noprefix, though.  Depending on the users, they would care just as
> deeply about any of these:
> 
> 	.context
> 	.interHunkContext
> 	.mnemonicPrefix
>         .noprefix
> 	.relative
> 	.orderFile
> 
> as Nikita does for .noprefix to send a bug report.
> 
> Luckily or unluckily, .suppressBlankEmpty and the per-filetype
> .xfuncname patterns do impact the output from the plumbing, because
> git_diff_basic_config() does read them, even though they are merely
> "cosmetic" configurations.
> 
> I am unsure how much we should cater to end-user controlled
> configuration when we are generating diff output for our own
> consumption, but if we were to tweak "add -p" and friends to
> pay attention to .noprefix, we probably should do the same for
> all the others.

Yes. We already have gone through this with other options (e.g.,
diff.algorithm). I would be happy if somebody wanted to handle the
complete set. But I am also OK with stumbling towards completeness, as
people who care about a particular option plumb it through.

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-06 22:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-06 10:15 [Bug report] diff.noprefix config is ignored for interactive `add` Nikita Bobko
2021-04-06 21:36 ` Jeff King
2021-04-06 21:57   ` Junio C Hamano
2021-04-06 22:47     ` Jeff King

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git