changeset 169:f1919e1c35bf

fetch_command: cancel patching when encountering binary diffs Mercurial patching code does not support hunks with embedded nul characters.
author Patrick Mezard <pmezard@gmail.com>
date Tue, 30 Dec 2008 20:33:56 -0600
parents 4f26fa049452
children d046bef502d7
files fetch_command.py tests/fixtures/binaryfiles.sh tests/fixtures/binaryfiles.svndump tests/run.py tests/test_binaryfiles.py
diffstat 5 files changed, 59 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_command.py
+++ b/fetch_command.py
@@ -229,6 +229,8 @@ def stupid_diff_branchrev(ui, svn, hg_ed
         if (hasattr(e, 'apr_err') and e.apr_err != 160013):
             raise
         raise BadPatchApply('previous revision does not exist')
+    if '\0' in d:
+        raise BadPatchApply('binary diffs are not supported')
     files_data = {}
     binary_files = {}
     touched_files = {}
new file mode 100755
--- /dev/null
+++ b/tests/fixtures/binaryfiles.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Generate binaryfiles.svndump
+#
+
+mkdir temp
+cd temp
+
+mkdir project-orig
+cd project-orig
+mkdir trunk
+cd ..
+
+svnadmin create testrepo
+svnurl=file://`pwd`/testrepo
+svn import project-orig $svnurl -m "init project"
+
+svn co $svnurl project
+cd project/trunk
+# Add a regular binary file, and an unflagged one
+python -c "file('binary1', 'wb').write('a\0\0\nb\0b')"
+python -c "file('binary2', 'wb').write('b\0\0\nc\0d')"
+svn add binary1 binary2
+svn propset svn:mime-type application/octet-stream binary1
+svn propdel svn:mime-type binary2
+svn ci -m 'add binaries'
+# Update them
+python -c "file('binary1', 'wb').write('a\0\0\nc\0d')"
+python -c "file('binary2', 'wb').write('b\0\0\0\nd\0e')"
+svn ci -m 'change binaries'
+# Remove them
+svn rm binary1 binary2
+svn ci -m 'remove binaries'
+cd ../..
+
+svnadmin dump testrepo > ../binaryfiles.svndump
new file mode 100644
index 0000000000000000000000000000000000000000..9317774582e19bb0031a149757920c9e853197ca
GIT binary patch
literal 1886
zc$}?NNp9OP6!n^?&;^)q9<*(`C<>%OrbTxgz8p2y0GT$Lp1!n#01hOlZtSHVDZLT8
zd%VWg8plo3<Ek4Pm+%&bb=|dP!4P_Q_;ytm!W$kmGgxxPu&|C}XEei=<-&rcwyF$5
zx3H~uFXDF7co@oppqruVap>9vZNe*Pm+7f2q(Wb&5c*yiwBEL5bP3R7!8Bro7)%*v
z_MYmJsFKMG%7qf*C%U=)adU^iUSG}d(s^D=#e{f=WoA7xuexO>rVQ0>or-?wenCk2
zl#=n-ZPHUW<Qp3G4g7IKJXW){jO%xrue%7icRLAb*tE~Dz;oTkvWWHY`shL$dvGxx
za73nt2-@eFhQm$`C#xxZ-MXQM^~vF=3ob~8KMdz`q<f+JAyxGXj!a2fbPvDN1lRB3
zCdzEtSjiknZv`c^@{(H{m?N4B2||ZSMrvFx<)hQ4ZUCp3ezYr)>-$w5+)mzQ7ZN1A
zP6N1R&#PN3kYD(Np4lfo=T?sP%r(<e6Cxz#PDDz%sXWX6d9*QlIo*Zc-<Z!9!XnO0
zjUSqto|&4SOiiNj<k}^iZ*BU52}X%M!`fb@9UroA+9++UARuJ4ArM|k!MqCqo-jK}
zB<JDYlKtE`K9XqWcHpS8Q5vs^4T=!1xba%)%DO5DVkQ#vKR=hhKyd*x?Tb^}AE4>B
bXKdf(AF<*}{zv<7QASun{_ww=m|Xu0)b>EF
--- a/tests/run.py
+++ b/tests/run.py
@@ -4,6 +4,7 @@ import unittest
 
 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
+import test_binaryfiles
 import test_diff
 import test_fetch_branches
 import test_fetch_command
@@ -22,7 +23,8 @@ import test_tags
 import test_utility_commands
 
 def suite():
-    return unittest.TestSuite([test_diff.suite(),
+    return unittest.TestSuite([test_binaryfiles.suite(),
+                               test_diff.suite(),
                                test_fetch_branches.suite(),
                                test_fetch_command.suite(),
                                test_fetch_command_regexes.suite(),
new file mode 100644
--- /dev/null
+++ b/tests/test_binaryfiles.py
@@ -0,0 +1,18 @@
+import unittest
+
+from mercurial import node
+
+import test_util
+
+class TestFetchBinaryFiles(test_util.TestBase):
+    def test_binaryfiles(self, stupid=False):
+        repo = self._load_fixture_and_fetch('binaryfiles.svndump', stupid=stupid)
+        self.assertEqual('cce7fe400d8d', str(repo['tip']))
+
+    def test_binaryfiles_stupid(self):
+        self.test_binaryfiles(True)
+
+def suite():
+    all = [unittest.TestLoader().loadTestsFromTestCase(TestFetchBinaryFiles),
+          ]
+    return unittest.TestSuite(all)