Python difflib gnu 补丁兼容性
可以使用与 GNU 补丁兼容的 python 模块 difflib 创建补丁吗? 我尝试使用 Unified_diff 和 context_diff 并尝试将 lineterm 指定为“\n”,但我仍然收到此错误:
[intense@Singularity Desktop]$ patch diff.patch test.txt
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.
我使用 file.writelines(diff) 将补丁写入文件(代码段 http://pastebin.com/3HAWfwVf)
文件 test.txt:
Hello, this is test
blah
文件 test2.txt:
Hello, this is test
blah, dfsgjdfgj
lfkdjgkldfjgkldfjgkl
并生成补丁:
--- /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
感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会使用mercurials bdiff 模块,它比difflib 快得多。
I'd use mercurials bdiff module, which is considerably faster than difflib.
diff -rNau dir-v1/ dir-v2/ > 1-2.patch
instead of difflib.