diff mercurial/mdiff.py @ 4679:826659bd8053

git patches: correct handling of filenames with spaces Add a trailing TAB to the "--- filename" lines if there's a space in the file name. This allows patch(1) to work correctly. The same is done for diff --nodates. This was originally suggested by Andrei Vermel, but at the time I thought git was doing something different.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Fri, 22 Jun 2007 19:06:04 -0300
parents 99c853a1408c
children 372d93f03d3a
line wrap: on
line diff
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -50,8 +50,12 @@ class diffopts(object):
 defaultopts = diffopts()
 
 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts):
-    def datetag(date):
-        return (opts.git or opts.nodates) and '\n' or '\t%s\n' % date
+    def datetag(date, addtab=True):
+        if not opts.git and not opts.nodates:
+            return '\t%s\n' % date
+        if addtab and ' ' in fn:
+            return '\t\n'
+        return '\n'
 
     if not a and not b: return ""
     epoch = util.datestr((0, 0))
@@ -66,7 +70,7 @@ def unidiff(a, ad, b, bd, fn, r=None, op
     elif not a:
         b = splitnewlines(b)
         if a is None:
-            l1 = '--- /dev/null%s' % datetag(epoch)
+            l1 = '--- /dev/null%s' % datetag(epoch, False)
         else:
             l1 = "--- %s%s" % ("a/" + fn, datetag(ad))
         l2 = "+++ %s%s" % ("b/" + fn, datetag(bd))
@@ -76,7 +80,7 @@ def unidiff(a, ad, b, bd, fn, r=None, op
         a = splitnewlines(a)
         l1 = "--- %s%s" % ("a/" + fn, datetag(ad))
         if b is None:
-            l2 = '+++ /dev/null%s' % datetag(epoch)
+            l2 = '+++ /dev/null%s' % datetag(epoch, False)
         else:
             l2 = "+++ %s%s" % ("b/" + fn, datetag(bd))
         l3 = "@@ -1,%d +0,0 @@\n" % len(a)