Don't generate git diff header for empty diffs
authorBrendan Cully <brendan@kublai.com>
Tue, 10 Oct 2006 14:48:26 -0700
changeset 3329 319358e6bd96
parent 3328 415905fad4fe
child 3331 f472cf9a71af
Don't generate git diff header for empty diffs
mercurial/patch.py
--- a/mercurial/patch.py	Tue Oct 10 10:54:22 2006 -0700
+++ b/mercurial/patch.py	Tue Oct 10 14:48:26 2006 -0700
@@ -467,6 +467,7 @@
         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 @@
                     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 @@
                     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):