Python difflib gnu patch compatibility
It's possible to create patch with python module difflib which is compatible with GNU patch? I tried to use unified_diff and context_diff and also tried to specify lineterm as "\n" but I'm still gettings this error:
[intense@Singularity Desktop]$ patch diff.patch test.txt
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.
I used开发者_如何学运维 file.writelines(diff) to write patch into file (Piece of code http://pastebin.com/3HAWfwVf)
File test.txt:
Hello, this is test
blah
File test2.txt:
Hello, this is test
blah, dfsgjdfgj
lfkdjgkldfjgkldfjgkl
And generated patch:
--- /home/intense/Desktop/test.txt
+++ /home/intense/Desktop/test2.txt
@@ -1,2 +1,7 @@
-Hello, this is test
-blah+Hello,+this+is+test+blah,+dfsgjdfgj+lfkdjgkldfjgkldfjgkl
Thanks for any help.
I'd use mercurials bdiff module, which is considerably faster than difflib.
- Try to use python-patch instead of the GNU patch utility to apply unified diffs,
- OR use
diff -rNau dir-v1/ dir-v2/ > 1-2.patch
instead of difflib.
精彩评论