Python compatibility difflib gnu

Can I create a patch with the difflib python module that is compatible with the GNU patch? I tried using unified_diff and context_diff, and also tried to specify lineterm as "\ n", but I'm still executing 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 the patch to a file (code snippet http://pastebin.com/3HAWfwVf )

File test.txt:

 Hello, this is test blah 

File test2.txt:

 Hello, this is test blah, dfsgjdfgj lfkdjgkldfjgkldfjgkl 

And the 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.

+4
source share
2 answers

I would use the bdiff mercurials module, which is significantly faster than difflib.

0
source
  • Try using python-patch instead of the GNU patch utility to apply uniform differences,
  • OR use diff -rNau dir-v1/ dir-v2/ > 1-2.patch instead of difflib.
0
source

Source: https://habr.com/ru/post/1369327/


All Articles