# HG changeset patch # User Brendan Cully # Date 2006-10-10 21:48:26 # Node ID 319358e6bd9652d757c8636e5177b3866087ac93 # Parent 415905fad4fed5997d69754d74de1a2cbc64ad65 Don't generate git diff header for empty diffs diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -467,6 +467,7 @@ def diff(repo, node1=None, node2=None, f to = None tn = None dodiff = True + header = [] if f in mmap: to = getfile(f).read(mmap[f]) if f not in removed: @@ -480,7 +481,6 @@ def diff(repo, node1=None, node2=None, f header.append('new mode %s\n' % nmode) a, b = f, f - header = [] if f in added: if node2: mode = gitmode(mmap2.execf(f)) @@ -510,11 +510,12 @@ def diff(repo, node1=None, node2=None, f nmode = gitmode(util.is_exec(repo.wjoin(f), mmap.execf(f))) addmodehdr(header, omode, nmode) r = None - if dodiff: - header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) + header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) + if dodiff: + text = mdiff.unidiff(to, date1, tn, date2(f), f, r, opts=opts) + if text or len(header) > 1: fp.write(''.join(header)) - if dodiff: - fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, opts=opts)) + fp.write(text) def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, opts=None):