1. Benoit Boissinot
  2. hgsubversion/python2.3

Commits

Patrick Mézard  committed f1919e1

fetch_command: cancel patching when encountering binary diffs

Mercurial patching code does not support hunks with embedded nul characters.

  • Participants
  • Parent commits 4f26fa0
  • Branches default

Comments (0)

Files changed (5)

File fetch_command.py

View file
         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 = {}

File tests/fixtures/binaryfiles.sh

View file
+#!/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

File tests/fixtures/binaryfiles.svndump

Binary file added.

File tests/run.py

View file
 
 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
 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(),

File tests/test_binaryfiles.py

View file
+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)