[Pkg-bazaar-commits] ./bzr/unstable r441: - Fix from Lalo for unidiff output of newly added

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:19:42 UTC 2009


------------------------------------------------------------
revno: 441
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Tue 2005-05-10 17:15:48 +1000
message:
  - Fix from Lalo for unidiff output of newly added 
    and changed files.
modified:
  NEWS
  bzrlib/diff.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-05-10 07:14:23 +0000
+++ b/NEWS	2005-05-10 07:15:48 +0000
@@ -36,6 +36,12 @@
     * New "stat cache" avoids reading the contents of files if they 
       haven't changed since the previous time.
 
+  
+  BUG FIXES:
+
+    * Fixed diff format so that added and removed files will be
+      handled properly by patch.  Fix from Lalo Martins.
+
 
   TESTING:
 

=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py	2005-05-05 09:26:27 +0000
+++ b/bzrlib/diff.py	2005-05-10 07:15:48 +0000
@@ -179,9 +179,6 @@
         # idlabel = '      {%s}' % fid
         idlabel = ''
 
-        # FIXME: Something about the diff format makes patch unhappy
-        # with newly-added files.
-
         def diffit(oldlines, newlines, **kw):
             
             # FIXME: difflib is wrong if there is no trailing newline.
@@ -210,6 +207,16 @@
                 nonl = True
 
             ud = difflib.unified_diff(oldlines, newlines, **kw)
+
+            # work-around for difflib being too smart for its own good
+            # if /dev/null is "1,0", patch won't recognize it as /dev/null
+            if not oldlines:
+                ud = list(ud)
+                ud[2] = ud[2].replace('-1,0', '-0,0')
+            elif not newlines:
+                ud = list(ud)
+                ud[2] = ud[2].replace('+1,0', '+0,0')
+            
             sys.stdout.writelines(ud)
             if nonl:
                 print "\\ No newline at end of file"



More information about the Pkg-bazaar-commits mailing list