Skip to contentSkip to conversation

git-jump: ignore (custom) prefix in diff mode

PATCH In review Mischa POSLAWSKY 5 participants 10 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-jump: ignore (custom) prefix in diff mode

Matching the default file prefix b/ does not yield any results if config option diff.noprefix or diff.mnemonicprefix is enabled.

---
Very useful script otherwise; thanks.

 contrib/git-jump/git-jump | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
git-jump/git-jump +2 -2
index a33674e..dc90cd6 100755
@@ -21,9 +21,9 @@ open_editor() {
 }
 
 mode_diff() {
-	git diff --relative "$@" |
+	git diff --no-prefix --relative "$@" |
 	perl -ne '
-	if (m{^\+\+\+ b/(.*)}) { $file = $1; next }
+	if (m{^\+\+\+ (.*)}) { $file = $1; next }
 	defined($file) or next;
 	if (m/^@@ .*\+(\d+)/) { $line = $1; next }
 	defined($line) or next;
Signature · 1 line
1.7.12.165.g8cb9d9c
#1 lore raw

git-jump/git-jump

Quoted 4 lines
git-jump/git-jump +0 -0
index a33674e..dc90cd6 100755

Apparently diff.noprefix also applies to git format-patch. Even though git am does explicitly support -p0, I would argue against diff options creating non-standard patches.

-- >8 --
Subject: [PATCH/RFC] format-patch: force default file prefixes in diff

Override user configuration (eg. diff.noprefix) in patches intended for external consumption to match the default prefixes expected by git-am.

---
 builtin/log.c | 2 ++
 1 file changed, 2 insertions(+)
builtin/log.c +2 -0
index dff7921..91ded25 100644
@@ -1131,6 +1131,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	rev.diff = 1;
 	rev.max_parents = 1;
 	DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
+	rev.diffopt.a_prefix = "a/";
+	rev.diffopt.b_prefix = "b/";
 	rev.subject_prefix = fmt_patch_subject_prefix;
 	memset(&s_r_opt, 0, sizeof(s_r_opt));
 	s_r_opt.def = "HEAD";
Signature · 1 line
1.7.12.166.ga54f379
#2 lore raw
Quoted 1 line · Mischa POSLAWSKY

... I would argue against diff options creating non-standard patches.

Seems to me it might depend on what one means by "non-standard".

I can envision cases in which increasing the number of context lines would result in the patch being more robust WRT applying correctly to a recipient's version that might be a bit different than the one against which it was created.

OTOH one most likely does not want to create a patch with -b unless the apply tool also supports such and there is a way to communicate to the apply tool that -b was used in creating the patch.

#3 lore raw
In reply to Mischa POSLAWSKY
Quoted 9 lines · Mischa POSLAWSKY

git-jump/git-jump

Quoted 4 lines
git-jump/git-jump +0 -0
index a33674e..dc90cd6 100755

Apparently diff.noprefix also applies to git format-patch. Even though git am does explicitly support -p0, I would argue against diff options creating non-standard patches.

Quoted 8 lines

-- >8 --
Subject: [PATCH/RFC] format-patch: force default file prefixes in diff

Override user configuration (eg. diff.noprefix) in patches intended for external consumption to match the default prefixes expected by git-am.

---

Not all projects expect to see a/ & b/ prefix and these are configurable for a reason. Robbing the choice that has been supported for quite a long time from them is an unacceptable regression.

Why did you think this may be a good idea in the first place?

Perhaps you had configured your diff.noprefix in a wrong configuration file? This is primarily per-project choice, and your clone of git.git should not have diff.noprefix set, neither your $HOME/.gitconfig unless you always work on projects that want diff.noprefix.

Quoted 16 lines
 builtin/log.c | 2 ++
 1 file changed, 2 insertions(+)
builtin/log.c +2 -0
index dff7921..91ded25 100644
@@ -1131,6 +1131,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	rev.diff = 1;
 	rev.max_parents = 1;
 	DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
+	rev.diffopt.a_prefix = "a/";
+	rev.diffopt.b_prefix = "b/";
 	rev.subject_prefix = fmt_patch_subject_prefix;
 	memset(&s_r_opt, 0, sizeof(s_r_opt));
 	s_r_opt.def = "HEAD";
#4 lore raw

Junio C Hamano skribis 2012-9-16 22:22 (-0700):

Quoted 7 lines
Quoted 5 lines · Mischa POSLAWSKY

Subject: [PATCH/RFC] format-patch: force default file prefixes in diff

Override user configuration (eg. diff.noprefix) in patches intended for external consumption to match the default prefixes expected by git-am.

Quoted 7 lines
Quoted 2 lines

---

Not all projects expect to see a/ & b/ prefix and these are configurable for a reason. Robbing the choice that has been supported for quite a long time from them is an unacceptable regression.

My bad, I was assuming format-patch would mostly interact with git am.

Quoted 7 lines

Why did you think this may be a good idea in the first place?

Perhaps you had configured your diff.noprefix in a wrong configuration file? This is primarily per-project choice, and your clone of git.git should not have diff.noprefix set, neither your $HOME/.gitconfig unless you always work on projects that want diff.noprefix.

Then I'm not using it as intended. For me it's just a personal preference of how I'd like to review commits (diff/show) so I can easily copy-paste file names (less essential since my discovery of git jump, but still). It's not something I'd like to be communicated with any upstream project (format-patch).

So it seems I'm asking for a new feature: to be able to configure local and inter-project diff options differently. In this case I'd be helped by either format.noprefix=0 or a to be bikeshedded localdiff.noprefix=1. I don't know about other options though. Does anybody actually want mnemonicprefix to be sent out as well?

Another solution could be a single option defining behaviour exceptions:
format.diff = normal | textconv | noconfig
Expanding on the existing --(no-)textconv difference in format-patch.

Signature · 1 line
Mischa
#5 lore raw
Quoted 7 lines · Mischa POSLAWSKY
Quoted 5 lines

Perhaps you had configured your diff.noprefix in a wrong configuration file? This is primarily per-project choice, and your clone of git.git should not have diff.noprefix set, neither your $HOME/.gitconfig unless you always work on projects that want diff.noprefix.

Then I'm not using it as intended.

I would imagine that you could do

	(in ~/.gitconfig)
	[diff] noprefix

        (in ~/git.git/.git/config
        [diff] noprefix = false

or something.

#6 lore raw
In reply to Mischa POSLAWSKY
Quoted 33 lines · Mischa POSLAWSKY

Junio C Hamano skribis 2012-9-16 22:22 (-0700):

Quoted 7 lines
Quoted 5 lines · Mischa POSLAWSKY

Subject: [PATCH/RFC] format-patch: force default file prefixes in diff

Override user configuration (eg. diff.noprefix) in patches intended for external consumption to match the default prefixes expected by git-am.

Quoted 7 lines
Quoted 2 lines

---

Not all projects expect to see a/ & b/ prefix and these are configurable for a reason. Robbing the choice that has been supported for quite a long time from them is an unacceptable regression.

My bad, I was assuming format-patch would mostly interact with git am.

Quoted 7 lines

Why did you think this may be a good idea in the first place?

Perhaps you had configured your diff.noprefix in a wrong configuration file? This is primarily per-project choice, and your clone of git.git should not have diff.noprefix set, neither your $HOME/.gitconfig unless you always work on projects that want diff.noprefix.

Then I'm not using it as intended. For me it's just a personal preference of how I'd like to review commits (diff/show) so I can easily copy-paste file names (less essential since my discovery of git jump, but still). It's not something I'd like to be communicated with any upstream project (format-patch).

Quoted 5 lines

So it seems I'm asking for a new feature: to be able to configure local and inter-project diff options differently. In this case I'd be helped by either format.noprefix=0 or a to be bikeshedded localdiff.noprefix=1. I don't know about other options though. Does anybody actually want mnemonicprefix to be sent out as well?

I once had the same idea and posted a patch for it:

http://article.gmane.org/gmane.comp.version-control.git/146215

The implementation differs though, the pure path without any mnemonicprefix is in its own line 'path <path>'. But my current patch also differs to this old one, in the current one, the path is at the end 'index' line. But I do not need this feature anymore.

Bert

Quoted 7 lines

Another solution could be a single option defining behaviour exceptions:
format.diff = normal | textconv | noconfig
Expanding on the existing --(no-)textconv difference in format-patch.

--
Mischa

#7 lore raw
In reply to Mischa POSLAWSKY
Quoted 16 lines · Mischa POSLAWSKY

Matching the default file prefix b/ does not yield any results if config option diff.noprefix or diff.mnemonicprefix is enabled.

---
Very useful script otherwise; thanks.

 contrib/git-jump/git-jump | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
git-jump/git-jump +0 -0
index a33674e..dc90cd6 100755
@@ -21,9 +21,9 @@ open_editor() {
 }

git-jump/git-jump open_editor() { · line 29

Quoted 10 lines
git-jump/git-jump +2 -2
 
 mode_diff() {
-	git diff --relative "$@" |
+	git diff --no-prefix --relative "$@" |
 	perl -ne '
-	if (m{^\+\+\+ b/(.*)}) { $file = $1; next }
+	if (m{^\+\+\+ (.*)}) { $file = $1; next }
 	defined($file) or next;
 	if (m/^@@ .*\+(\d+)/) { $line = $1; next }
 	defined($line) or next;

Makes sense to me. Peff?

Acked-by
#8 lore raw
Quoted 19 lines · Junio C Hamano
Quoted 17 lines · Mischa POSLAWSKY

Matching the default file prefix b/ does not yield any results if config option diff.noprefix or diff.mnemonicprefix is enabled.

---
Very useful script otherwise; thanks.

 contrib/git-jump/git-jump | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
git-jump/git-jump +0 -0
index a33674e..dc90cd6 100755
@@ -21,9 +21,9 @@ open_editor() {
 }
 
Quoted 11 lines

git-jump/git-jump open_editor() { · line 29

Quoted 9 lines
git-jump/git-jump +2 -2
 mode_diff() {
-	git diff --relative "$@" |
+	git diff --no-prefix --relative "$@" |
 	perl -ne '
-	if (m{^\+\+\+ b/(.*)}) { $file = $1; next }
+	if (m{^\+\+\+ (.*)}) { $file = $1; next }
 	defined($file) or next;
 	if (m/^@@ .*\+(\d+)/) { $line = $1; next }
 	defined($line) or next;

Makes sense to me. Peff?

Yes, looks obviously correct. Thanks.

-Peff

#9 lore raw
Quoted 23 lines · Jeff King
Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Mischa POSLAWSKY

Matching the default file prefix b/ does not yield any results if config option diff.noprefix or diff.mnemonicprefix is enabled.

---
Very useful script otherwise; thanks.

 contrib/git-jump/git-jump | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 8 lines

git-jump/git-jump open_editor() {

Quoted 6 lines
git-jump/git-jump +0 -0
index a33674e..dc90cd6 100755
@@ -21,9 +21,9 @@ open_editor() {
...

Makes sense to me. Peff?

Quoted 3 lines

Yes, looks obviously correct. Thanks.

Thanks.

It may not be obvious to many people, so here is tip of the day.

I knew Mischa knew that the patch was prepared with wrong src/dst prefix (notice the lack of a/ and b/), but I did not say anything special when I drove "git am". I just did the usual "git am -s3c" and the patch was applied just fine ;-)

What is happening is that:

- I didn't give '-p0" to "git am", so it thought that patch was based on a tree that has "git-jump" directory at the top-level of the working tree, and the file that is being patched lived at "git-jump/git-jump" in Mischa's working tree;

- However, the official git.git tree has the corresponding file at "contrib/git-jump/git-jump", and there is no such file at "git-jump/git-jump".

- The three-way merge logic kicks in because of the "-3" option, using a (fake) tree that is shaped like Mischa's tree with the version before the patch as a common ancestor, to merge the version "git am" thought Mischa has (i.e. no contrib/ directory) and the version in my tree. From the point of view of the three-way merge logic, I renamed the path to be in contrib/ directory while Mischa kept the path intact and fixed the contents of the script. This merges cleanly to produce the expected result.