Mercurial > public > mercurial-scm > hg-stable
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 Fri Jun 22 14:32:54 2007 -0300 +++ b/mercurial/mdiff.py Fri Jun 22 19:06:04 2007 -0300 @@ -50,8 +50,12 @@ 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 @@ 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 @@ 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)