Patchwork [5,of,6] policy: reroute proxy modules internally

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 8, 2017, 2:30 p.m.
Message ID <6713774405f9b183f550.1502202624@mimosa>
Download mbox | patch
Permalink /patch/22752/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 8, 2017, 2:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1501512036 -32400
#      Mon Jul 31 23:40:36 2017 +0900
# Node ID 6713774405f9b183f5500f65901f1dadbbd4639a
# Parent  9a77fc7505ac35764963080f38266b9e5cab0934
policy: reroute proxy modules internally

This allows us to split encoding functions from pure.parsers without doing
that for cext.parsers. See the next patch for why.

Patch

diff --git a/mercurial/cffi/base85.py b/mercurial/cffi/base85.py
deleted file mode 100644
--- a/mercurial/cffi/base85.py
+++ /dev/null
@@ -1,10 +0,0 @@ 
-# base85.py: pure python base85 codec
-#
-# Copyright (C) 2009 Brendan Cully <brendan@kublai.com>
-#
-# This software may be used and distributed according to the terms of the
-# GNU General Public License version 2 or any later version.
-
-from __future__ import absolute_import
-
-from ..pure.base85 import *
diff --git a/mercurial/cffi/diffhelpers.py b/mercurial/cffi/diffhelpers.py
deleted file mode 100644
--- a/mercurial/cffi/diffhelpers.py
+++ /dev/null
@@ -1,10 +0,0 @@ 
-# diffhelpers.py - pure Python implementation of diffhelpers.c
-#
-# Copyright 2009 Matt Mackall <mpm@selenic.com> and others
-#
-# This software may be used and distributed according to the terms of the
-# GNU General Public License version 2 or any later version.
-
-from __future__ import absolute_import
-
-from ..pure.diffhelpers import *
diff --git a/mercurial/cffi/parsers.py b/mercurial/cffi/parsers.py
deleted file mode 100644
--- a/mercurial/cffi/parsers.py
+++ /dev/null
@@ -1,10 +0,0 @@ 
-# parsers.py - Python implementation of parsers.c
-#
-# Copyright 2009 Matt Mackall <mpm@selenic.com> and others
-#
-# This software may be used and distributed according to the terms of the
-# GNU General Public License version 2 or any later version.
-
-from __future__ import absolute_import
-
-from ..pure.parsers import *
diff --git a/mercurial/policy.py b/mercurial/policy.py
--- a/mercurial/policy.py
+++ b/mercurial/policy.py
@@ -78,6 +78,13 @@  def _importfrom(pkgname, modname):
     (r'cext', r'parsers'): 1,
 }
 
+# map import request to other package or module
+_modredirects = {
+    (r'cffi', r'base85'): (r'pure', r'base85'),
+    (r'cffi', r'diffhelpers'): (r'pure', r'diffhelpers'),
+    (r'cffi', r'parsers'): (r'pure', r'parsers'),
+}
+
 def _checkmod(pkgname, modname, mod):
     expected = _cextversions.get((pkgname, modname))
     actual = getattr(mod, r'version', None)
@@ -94,11 +101,14 @@  def importmod(modname):
         raise ImportError(r'invalid HGMODULEPOLICY %r' % policy)
     assert verpkg or purepkg
     if verpkg:
+        pn, mn = _modredirects.get((verpkg, modname), (verpkg, modname))
         try:
-            mod = _importfrom(verpkg, modname)
-            _checkmod(verpkg, modname, mod)
+            mod = _importfrom(pn, mn)
+            if pn == verpkg:
+                _checkmod(pn, mn, mod)
             return mod
         except ImportError:
             if not purepkg:
                 raise
-    return _importfrom(purepkg, modname)
+    pn, mn = _modredirects.get((purepkg, modname), (purepkg, modname))
+    return _importfrom(pn, mn)