python-unidiff icon indicating copy to clipboard operation
python-unidiff copied to clipboard

Handle variations of git diff mnemonic prefixes

Open matiasb opened this issue 3 years ago • 2 comments

Right now, code assumes a/ and b/ prefixes for the filenames being compared. Those prefixes could be different depending on: http://git-scm.com/docs/diff-config#Documentation/diff-config.txt-diffmnemonicPrefix

matiasb avatar Jun 01 '21 12:06 matiasb

Here is another similar issue since unidiff 0.7.1 - contents generated by git diff --no-prefix is not correctly handled, either. For example, with the following diff:

diff --git file1 file1
deleted file mode 100644
index 42f90fd..0000000
--- file1
+++ /dev/null
@@ -1,3 +0,0 @@
-line11
-line12
-line13
diff --git file2 file2
index c337bf1..1cb02b9 100644
--- file2
+++ file2
@@ -4,0 +5,3 @@ line24
+line24n
+line24n2
+line24n3
@@ -15,0 +19,3 @@ line215
+line215n
+line215n2
+line215n3
diff --git file3 file3
new file mode 100644
index 0000000..632e269
--- /dev/null
+++ file3
@@ -0,0 +1,3 @@
+line31
+line32
+line33

(extracted from https://github.com/buildbot/buildbot/blob/v3.4.0/master/buildbot/test/unit/test_steps_git_diffinfo.py#L94-L123)

an exception is thrown:

$ python -c 'import unidiff; unidiff.PatchSet.from_filename("test.diff")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/yen/tmp/python-unidiff/unidiff/patch.py", line 591, in from_filename
    instance = cls(f)
  File "/home/yen/tmp/python-unidiff/unidiff/patch.py", line 460, in __init__
    self._parse(data, encoding=encoding, metadata_only=metadata_only)
  File "/home/yen/tmp/python-unidiff/unidiff/patch.py", line 505, in _parse
    raise UnidiffParseError('Unexpected deleted file found: %s' % line)
unidiff.errors.UnidiffParseError: Unexpected deleted file found: deleted file mode 100644

The same diff can be parsed with unidiff 0.7.0.

yan12125 avatar Jan 28 '22 12:01 yan12125

Hmm... I see the problem, will try to work in a fix in a bit.

matiasb avatar Jan 28 '22 15:01 matiasb