diff mercurial/patch.py @ 4108:226df1808f16

merge with crew-stable
author Thomas Arendsen Hein <thomas@intevation.de>
date Tue, 20 Feb 2007 20:55:23 +0100
parents 49237d6ae97d 797dbdd4d7e1
children ef4c1cd6f4e4
line wrap: on
line diff
--- a/mercurial/patch.py	Sat Feb 17 04:50:06 2007 -0200
+++ b/mercurial/patch.py	Tue Feb 20 20:55:23 2007 +0100
@@ -412,16 +412,18 @@
             yield text[i:i+csize]
             i += csize
 
-    if to == tn:
-        return
+    tohash = gitindex(to)
+    tnhash = gitindex(tn)
+    if tohash == tnhash:
+        return ""
+
     # TODO: deltas
-    l = len(tn)
-    fp.write('index %s..%s\nGIT binary patch\nliteral %s\n' %
-             (gitindex(to), gitindex(tn), len(tn)))
-
-    tn = ''.join([fmtline(l) for l in chunk(zlib.compress(tn))])
-    fp.write(tn)
-    fp.write('\n')
+    ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' %
+           (tohash, tnhash, len(tn))]
+    for l in chunk(zlib.compress(tn)):
+        ret.append(fmtline(l))
+    ret.append('\n')
+    return ''.join(ret)
 
 def diff(repo, node1=None, node2=None, files=None, match=util.always,
          fp=None, changes=None, opts=None):
@@ -578,14 +580,14 @@
                     dodiff = 'binary'
             r = None
             header.insert(0, 'diff --git a/%s b/%s\n' % (a, b))
-        if dodiff == 'binary':
-            fp.write(''.join(header))
-            b85diff(fp, to, tn)
-        elif dodiff:
-            text = mdiff.unidiff(to, date1,
-                                 # ctx2 date may be dynamic
-                                 tn, util.datestr(ctx2.date()),
-                                 f, r, opts=opts)
+        if dodiff:
+            if dodiff == 'binary':
+                text = b85diff(fp, to, tn)
+            else:
+                text = mdiff.unidiff(to, date1,
+                                    # ctx2 date may be dynamic
+                                    tn, util.datestr(ctx2.date()),
+                                    f, r, opts=opts)
             if text or len(header) > 1:
                 fp.write(''.join(header))
             fp.write(text)