2011-08-27 61 views
4

可以使用與GNU補丁兼容的python模塊difflib創建補丁嗎? 我試圖用unified_diff和context_diff也試圖指定lineterm爲「\ n」,但我還是gettings此錯誤:Python difflib gnu補丁兼容性

[[email protected] Desktop]$ patch diff.patch test.txt 
patch unexpectedly ends in middle of line 
patch: **** Only garbage was found in the patch input. 

我用file.writelines(差異)來編寫補丁放到文件(件代碼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 

感謝您的幫助。

回答

0

我會使用mercurials bdiff模塊,這比difflib快得多。

+1

我在哪裏可以找到它? –

0
  1. 嘗試使用python-patch代替GNU補丁程序適用統一區別,
  2. OR使用diff -rNau dir-v1/ dir-v2/ > 1-2.patch代替difflib。