changeset 4092:4ced663bebf0

git patches: handle renames of binary files
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Fri, 16 Feb 2007 04:54:46 -0200
parents 3d7480ada3e5
children 669f99f78db0
files mercurial/patch.py tests/test-git-export tests/test-git-export.out
diffstat 3 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -412,6 +412,8 @@ def b85diff(fp, to, tn):
             yield text[i:i+csize]
             i += csize
 
+    if to == tn:
+        return
     # TODO: deltas
     l = len(tn)
     fp.write('index %s..%s\nGIT binary patch\nliteral %s\n' %
@@ -593,8 +595,8 @@ def diff(repo, node1=None, node2=None, f
                     to = getfile(a).read(arev)
                 else:
                     header.append('new file mode %s\n' % mode)
-                    if util.binary(tn):
-                        dodiff = 'binary'
+                if util.binary(tn):
+                    dodiff = 'binary'
             elif f in removed:
                 if f in srcs:
                     dodiff = False
--- a/tests/test-git-export
+++ b/tests/test-git-export
@@ -61,6 +61,11 @@ hg import -mfoo b.diff
 cmp binfile.bin $TESTDIR/binfile.bin
 
 echo
+echo '% rename binary file'
+hg mv binfile.bin renamed.bin
+hg diff --git
+
+echo
 echo '% diff across many revisions'
 hg mv dst dst2
 hg ci -m 'mv dst dst2' -d '0 0'
--- a/tests/test-git-export.out
+++ b/tests/test-git-export.out
@@ -66,6 +66,11 @@ fQItJW-{SoTm)8|5##k|m00000NkvXXu0mjf{mKw
 % import binary diff
 applying b.diff
 
+% rename binary file
+diff --git a/binfile.bin b/renamed.bin
+rename from binfile.bin
+rename to renamed.bin
+
 % diff across many revisions
 diff --git a/dst2 b/dst3
 rename from dst2