[PATCH 07 of 10] mpatch: switch to policy importer

Yuya Nishihara yuya at tcha.org
Sat May 20 04:41:14 EDT 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1471058338 -32400
#      Sat Aug 13 12:18:58 2016 +0900
# Node ID 354d8983dc0596b6ba1491084a9bfc0ee04ed188
# Parent  a81738a0469135083ffaec9b5cbd4a7a7f77e838
mpatch: switch to policy importer

diff --git a/contrib/check-py3-compat.py b/contrib/check-py3-compat.py
--- a/contrib/check-py3-compat.py
+++ b/contrib/check-py3-compat.py
@@ -17,7 +17,6 @@ import traceback
 
 # Modules that have both Python and C implementations.
 _dualmodules = (
-    'mpatch.py',
     'parsers.py',
 )
 
diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -26,7 +26,6 @@ allowsymbolimports = (
 
 # Modules that have both Python and C implementations.
 _dualmodules = (
-    'mpatch.py',
     'parsers.py',
 )
 
diff --git a/contrib/wix/dist.wxs b/contrib/wix/dist.wxs
--- a/contrib/wix/dist.wxs
+++ b/contrib/wix/dist.wxs
@@ -15,7 +15,7 @@
           <File Name="mercurial.cext.base85.pyd" />
           <File Name="mercurial.cext.bdiff.pyd" />
           <File Name="mercurial.cext.diffhelpers.pyd" />
-          <File Name="mercurial.mpatch.pyd" />
+          <File Name="mercurial.cext.mpatch.pyd" />
           <File Name="mercurial.cext.osutil.pyd" />
           <File Name="mercurial.parsers.pyd" />
           <File Name="pyexpat.pyd" />
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -23,7 +23,6 @@ modulepolicy = policy.policy
 # Modules that have both Python and C implementations. See also the
 # set of .py files under mercurial/pure/.
 _dualmodules = {
-    'mercurial.mpatch',
     'mercurial.parsers',
 }
 
diff --git a/mercurial/mpatch_module.c b/mercurial/cext/mpatch.c
rename from mercurial/mpatch_module.c
rename to mercurial/cext/mpatch.c
--- a/mercurial/mpatch_module.c
+++ b/mercurial/cext/mpatch.c
@@ -179,7 +179,7 @@ PyMODINIT_FUNC PyInit_mpatch(void)
 	if (m == NULL)
 		return NULL;
 
-	mpatch_Error = PyErr_NewException("mercurial.mpatch.mpatchError",
+	mpatch_Error = PyErr_NewException("mercurial.cext.mpatch.mpatchError",
 					  NULL, NULL);
 	Py_INCREF(mpatch_Error);
 	PyModule_AddObject(m, "mpatchError", mpatch_Error);
@@ -193,7 +193,7 @@ initmpatch(void)
 {
 	PyObject *m;
 	m = Py_InitModule3("mpatch", methods, mpatch_doc);
-	mpatch_Error = PyErr_NewException("mercurial.mpatch.mpatchError",
+	mpatch_Error = PyErr_NewException("mercurial.cext.mpatch.mpatchError",
 					  NULL, NULL);
 	PyModule_AddIntConstant(m, "version", version);
 }
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -986,12 +986,10 @@ def debuginstall(ui, **opts):
     if policy.policy in ('c', 'allow'):
         err = None
         try:
-            from . import (
-                mpatch,
-            )
             from .cext import (
                 base85,
                 bdiff,
+                mpatch,
                 osutil,
             )
             dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes
diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -14,13 +14,13 @@ import zlib
 from .i18n import _
 from . import (
     error,
-    mpatch,
     policy,
     pycompat,
     util,
 )
 
 bdiff = policy.importmod(r'bdiff')
+mpatch = policy.importmod(r'mpatch')
 
 blocks = bdiff.blocks
 fixws = bdiff.fixws
diff --git a/mercurial/pure/mpatch.py b/mercurial/pure/mpatch.py
--- a/mercurial/pure/mpatch.py
+++ b/mercurial/pure/mpatch.py
@@ -9,7 +9,7 @@ from __future__ import absolute_import
 
 import struct
 
-from . import policy, pycompat
+from .. import policy, pycompat
 stringio = pycompat.stringio
 modulepolicy = policy.policy
 policynocffi = policy.policynocffi
@@ -167,4 +167,3 @@ if modulepolicy not in policynocffi:
             res = ffi.buffer(buf, outlen)[:]
             lib.mpatch_lfree(patch)
             return res
-
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -631,8 +631,8 @@ extmodules = [
     Extension('mercurial.cext.diffhelpers', ['mercurial/cext/diffhelpers.c'],
               include_dirs=common_include_dirs,
               depends=common_depends),
-    Extension('mercurial.mpatch', ['mercurial/mpatch.c',
-                                   'mercurial/mpatch_module.c'],
+    Extension('mercurial.cext.mpatch', ['mercurial/mpatch.c',
+                                        'mercurial/cext/mpatch.c'],
               include_dirs=common_include_dirs,
               depends=common_depends),
     Extension('mercurial.parsers', ['mercurial/dirs.c',
diff --git a/tests/test-revlog.t b/tests/test-revlog.t
--- a/tests/test-revlog.t
+++ b/tests/test-revlog.t
@@ -12,4 +12,4 @@ Test for CVE-2016-3630
        0         0      19     -1       2 99e0332bd498 000000000000 000000000000
        1        19      12      0       3 6674f57a23d8 99e0332bd498 000000000000
   $ hg debugdata a.i 1 2>&1 | egrep 'Error:.*decoded'
-  (mercurial.mpatch.)?mpatchError: patch cannot be decoded (re)
+  (mercurial\.\w+\.mpatch\.)?mpatchError: patch cannot be decoded (re)


More information about the Mercurial-devel mailing list