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

Bug Report

Open Marvinmw opened this issue 4 years ago • 2 comments

There is a case unidiff cannot load the diff file that have the rename file, It outputs the error unknown trailling newline. For example,

'From 82dd164bbedcd025ef38a2fb374dd18b90c84828 Mon Sep 17 00:00:00 2001\n', 'From: Qiujuer [email protected]\n', 'Date: Thu, 10 Jul 2014 16:34:42 +0800\n', 'Subject: [PATCH] Rename JSONHelper to JSONHelper.java\n', '\n', '---\n', ' JSONHelper => JSONHelper.java | 0\n', ' 1 file changed, 0 insertions(+), 0 deletions(-)\n', ' rename JSONHelper => JSONHelper.java (100%)\n', '\n', 'diff --git a/JSONHelper b/JSONHelper.java\n', 'similarity index 100%\n', 'rename from JSONHelper\n', 'rename to JSONHelper.java\n', '-- \n', '2.17.1\n', '\n'

Marvinmw avatar Jun 24 '20 09:06 Marvinmw

Just encountered this myself, this is due to the trailing signature. Quoting from git format-patch --help:

       --[no-]signature=<signature>
           Add a signature to each message produced. Per RFC 3676 the signature is separated from the body by a line with '-- ' on it. If the signature option is omitted the signature defaults to the Git version number.

As far as I can tell, python-unidiff is trying to consume the trailing lines that belong to the signature as parts of the renamed PatchedFile. I worked around the issue by re-exporting my patches with --no-signature. I would guess that to parse this properly, the library needs to be made aware of this separator and accumulate this into a signature field on the PatchSet.

Thanks for the extra details, will take a look.

matiasb avatar Jul 20 '20 15:07 matiasb