comparison 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
comparison
equal deleted inserted replaced
4678:a814a5b11fff 4679:826659bd8053
48 setattr(self, k, v) 48 setattr(self, k, v)
49 49
50 defaultopts = diffopts() 50 defaultopts = diffopts()
51 51
52 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts): 52 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts):
53 def datetag(date): 53 def datetag(date, addtab=True):
54 return (opts.git or opts.nodates) and '\n' or '\t%s\n' % date 54 if not opts.git and not opts.nodates:
55 return '\t%s\n' % date
56 if addtab and ' ' in fn:
57 return '\t\n'
58 return '\n'
55 59
56 if not a and not b: return "" 60 if not a and not b: return ""
57 epoch = util.datestr((0, 0)) 61 epoch = util.datestr((0, 0))
58 62
59 if not opts.text and (util.binary(a) or util.binary(b)): 63 if not opts.text and (util.binary(a) or util.binary(b)):
64 return "" 68 return ""
65 l = ['Binary file %s has changed\n' % fn] 69 l = ['Binary file %s has changed\n' % fn]
66 elif not a: 70 elif not a:
67 b = splitnewlines(b) 71 b = splitnewlines(b)
68 if a is None: 72 if a is None:
69 l1 = '--- /dev/null%s' % datetag(epoch) 73 l1 = '--- /dev/null%s' % datetag(epoch, False)
70 else: 74 else:
71 l1 = "--- %s%s" % ("a/" + fn, datetag(ad)) 75 l1 = "--- %s%s" % ("a/" + fn, datetag(ad))
72 l2 = "+++ %s%s" % ("b/" + fn, datetag(bd)) 76 l2 = "+++ %s%s" % ("b/" + fn, datetag(bd))
73 l3 = "@@ -0,0 +1,%d @@\n" % len(b) 77 l3 = "@@ -0,0 +1,%d @@\n" % len(b)
74 l = [l1, l2, l3] + ["+" + e for e in b] 78 l = [l1, l2, l3] + ["+" + e for e in b]
75 elif not b: 79 elif not b:
76 a = splitnewlines(a) 80 a = splitnewlines(a)
77 l1 = "--- %s%s" % ("a/" + fn, datetag(ad)) 81 l1 = "--- %s%s" % ("a/" + fn, datetag(ad))
78 if b is None: 82 if b is None:
79 l2 = '+++ /dev/null%s' % datetag(epoch) 83 l2 = '+++ /dev/null%s' % datetag(epoch, False)
80 else: 84 else:
81 l2 = "+++ %s%s" % ("b/" + fn, datetag(bd)) 85 l2 = "+++ %s%s" % ("b/" + fn, datetag(bd))
82 l3 = "@@ -1,%d +0,0 @@\n" % len(a) 86 l3 = "@@ -1,%d +0,0 @@\n" % len(a)
83 l = [l1, l2, l3] + ["-" + e for e in a] 87 l = [l1, l2, l3] + ["-" + e for e in a]
84 else: 88 else: