[PATCH] diff: fix binary file removals in git mode

Sean Farley sean.michael.farley at gmail.com
Fri Mar 22 17:49:07 CDT 2013


# HG changeset patch
# User Johan Bjork <jbjoerk at gmail.com>
# Date 1362436451 0
#      Mon Mar 04 22:34:11 2013 +0000
# Node ID 61208f15fe3d5f28de7c5c75858c180f033024b5
# Parent  ac0336471ba766cc3c1234473e75d4478819e50d
diff: fix binary file removals in git mode.

With the previous version, a binary file removal diff generated with
diff --git would not apply with 'git apply' with the error
"
error: removal patch leaves file contents
error: <file>: patch does not apply
"

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1754,10 +1754,12 @@
                          and copy[copyto[f]] == f)):
                         dodiff = False
                     else:
                         header.append('deleted file mode %s\n' %
                                       gitmode[man1.flags(f)])
+                        if util.binary(to):
+                            dodiff = 'binary'
                 elif not to or util.binary(to):
                     # regular diffs cannot represent empty file deletion
                     losedatafn(f)
             else:
                 oflag = man1.flags(f)
diff --git a/tests/test-diff-upgrade.t b/tests/test-diff-upgrade.t
--- a/tests/test-diff-upgrade.t
+++ b/tests/test-diff-upgrade.t
@@ -198,20 +198,25 @@
   deleted file mode 100644
   
   % git=auto: git diff for rmbinary
   diff --git a/rmbinary b/rmbinary
   deleted file mode 100644
-  Binary file rmbinary has changed
+  index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000
+  GIT binary patch
+  literal 0
+  Hc$@<O00001
+  
   
   % git=auto: git diff for bintoregular
   diff --git a/bintoregular b/bintoregular
   index f76dd238ade08917e6712764a16a22005a50573d..9c42f2b6427d8bf034b7bc23986152dc01bfd3ab
   GIT binary patch
   literal 13
   Uc$`bh%qz(+N=+}#Ni5<5043uE82|tP
   
 
+
 git=warn: regular diff with data loss warnings
 
   $ hg autodiff --git=warn
   diff -r a66d19b9302d binary
   Binary file binary has changed


More information about the Mercurial-devel mailing list