سؤال

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.

نصائح أخرى

  1. Try to use python-patch instead of the GNU patch utility to apply unified diffs,
  2. OR use diff -rNau dir-v1/ dir-v2/ > 1-2.patch instead of difflib.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top