Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle variations of git diff mnemonic prefixes #81

Open
matiasb opened this issue Jun 1, 2021 · 2 comments
Open

Handle variations of git diff mnemonic prefixes #81

matiasb opened this issue Jun 1, 2021 · 2 comments

Comments

@matiasb
Copy link
Owner

matiasb commented Jun 1, 2021

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

@yan12125
Copy link

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.

@matiasb
Copy link
Owner Author

matiasb commented Jan 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants