Jump to content


Photo

Unix diff/patch tools and end of file woes


  • Please log in to reply
1 reply to this topic

#1 agb1

agb1
  • Member
  • 1623 posts

Posted 04 November 2016 - 02:08 PM

Does anyone know how to write a unified diff so that it will not add lines as duplicate that are already there at the end of a file?

 

The end of file is key, because there's no context below to cause the matching to fail.

 

Specifically, here is what happened:

 

I applied this patch:
 
@@ -172,3 +172,7 @@
         
     EXTEND_BOTTOM ~dwface04.bcs~ ~fadingpromises/script/b!dwface04.baf~ 
 END 
+ELSE BEGIN
+    COPY_EXISTING ~UDTRAP04.cre~ ~override~
+        ADD_CRE_ITEM ~b!amace~ #0 #0 #0 ~IDENTIFIED~ ~INV16~
+END
 
To a file that already had those lines at the end (this is before patching):
 
     EXTEND_BOTTOM ~dwface04.bcs~ ~fadingpromises/script/b!dwface04.baf~ 
 END 
 ELSE BEGIN
     COPY_EXISTING ~UDTRAP04.cre~ ~override~
         ADD_CRE_ITEM ~b!amace~ #0 #0 #0 ~IDENTIFIED~ ~INV16~
 END
 
Which resulted in this:
 
     EXTEND_BOTTOM ~dwface04.bcs~ ~fadingpromises/script/b!dwface04.baf~ 
 END 
 ELSE BEGIN
     COPY_EXISTING ~UDTRAP04.cre~ ~override~
         ADD_CRE_ITEM ~b!amace~ #0 #0 #0 ~IDENTIFIED~ ~INV16~
 END
 ELSE BEGIN
     COPY_EXISTING ~UDTRAP04.cre~ ~override~
         ADD_CRE_ITEM ~b!amace~ #0 #0 #0 ~IDENTIFIED~ ~INV16~
 END
 
Section in red was added by the patcher, because from its perspective, it saw the two lines above (green) as a match and didn't look beyond because when the patch was originally created, the file ended after those two green lines.
 
Any tips on how to handle this situation?

 


BiG World Fixpack (community collection of mod fixes and compatibility patches, with user-friendly cross-platform script)

 

BiG World Setup (tool to automate best-practice installation of Infinity Engine mods on Windows, with conflict analysis)

Latest version:    https://bitbucket.or.../get/master.zip


#2 Fouinto

Fouinto
  • Member
  • 458 posts

Posted 05 November 2016 - 01:40 AM

increasing --context[=nb] (with nb >3) should make the localization of the patch more reliable.

 

Edit : when making the diff file

Edit 2 : in fact, not sure if you need --unified[=nb] or --context[=nb]


Edited by Fouinto, 05 November 2016 - 01:44 AM.