Delta: ๐Ÿ› Handle diff.mnemonicPrefix

Created on 3 Jun 2020  ยท  3Comments  ยท  Source: dandavison/delta

Committed file:

$ git show HEAD:diff-test.txt
foo
    bar
return parent_names + [self.tree_name.value]

foo
bar

Uncommitted changes done to the diff-test.txt file (without renaming it):

$ git status -s
 M diff-test.txt

Uncommitted contents of the file:

$ cat diff-test.txt
foo yeah
    bar
parent_names += (self.tree_name.value,)
if include_module_names:
    skdjfh
    kjlkfjs
return parent_names

foo-one
bar-two

Diff as shown by git -P diff:

diff --git i/diff-test.txt w/diff-test.txt
index 5fd0037..3f0bbd0 100644
--- i/diff-test.txt
+++ w/diff-test.txt
@@ -1,6 +1,10 @@
-foo
+foo yeah
    bar
-return parent_names + [self.tree_name.value]
+parent_names += (self.tree_name.value,)
+if include_module_names:
+   skdjfh
+   kjlkfjs
+return parent_names

-foo
-bar
+foo-one
+bar-two

Delta shows the file as renamed:

$ git diff | delta

renamed: i/diff-test.txt โŸถ   w/diff-test.txt
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ‹ฎ

(Originally reported in #205)

All 3 comments

Ah-ha! I was wondering what these i/ and w/ prefixes are, but I see you must have diff.mnemonicPrefix set in your ~/.gitconfig. I had never heard of that option. (Perhaps it is time for me to study the git manual to try to find other things like this that are going to cause problems.)

Currently a/ and b/ are the only hard-coded prefixes and, when determining the file name, delta strips them if it sees them. But delta also understands not to demand that they are present (i.e. in this way delta handles the possibility that diff.noprefix is in effect.)

It seems like the obvious way forwards is to also hard-code i/w, c/w, c/i, o/w as known prefixes so that delta strips them if it sees them.

There is a pathological edge-case whereby a difficult user has --no-prefix set and also has directories genuinely named a/ and b/, but I believe this edge-case only affects a/ and b/ (since under diff.noprefix the other letters would indicate genuine directories.)

Correcting myself (hopefully I don't say something wrong again):

It seems like the obvious way forwards is to also hard-code i/w, c/w, c/i, o/w as known prefixes so that delta strips them if it sees them.

The upside of that is it will fix things for users with diff.mnemonicPrefix set.

The downside is that there are more ways it can be incorrect for users who have genuine single-letter directories.

Probably upside > downside?

I went ahead and hard-coded the additional prefixes, so your diff should be displayed correctly in master.

Was this page helpful?
0 / 5 - 0 ratings