[PATCH 03 of 12] base85: proxy through util module

Yuya Nishihara yuya at tcha.org
Sat May 6 21:45:44 EDT 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1493211407 -32400
#      Wed Apr 26 21:56:47 2017 +0900
# Node ID 788c58f59682a4d82d1b69c974058761897ebe44
# Parent  9151ab042bb7e3001d0a2a4fdb8f435928504d36
base85: proxy through util module

I'm going to replace hgimporter with a simpler import function, so we can
access to pure/cext modules by name:

  # util.py
  base85 = policy.importmod('base85')  # select pure.base85 or cext.base85

  # cffi/base85.py
  from ..pure.base85 import *  # may re-export pure.base85 functions

This means we'll have to use policy.importmod() function in place of the
standard import statement, but we wouldn't want to write it every place where
C extension modules are used. So this patch makes util host base85 functions.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -16,7 +16,6 @@ from .node import (
     nullid,
 )
 from . import (
-    base85,
     bookmarks as bookmod,
     bundle2,
     changegroup,
@@ -1509,7 +1508,7 @@ def _pullobsolete(pullop):
             markers = []
             for key in sorted(remoteobs, reverse=True):
                 if key.startswith('dump'):
-                    data = base85.b85decode(remoteobs[key])
+                    data = util.b85decode(remoteobs[key])
                     version, newmarks = obsolete._readmarkers(data)
                     markers += newmarks
             if markers:
diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -13,7 +13,6 @@ import zlib
 
 from .i18n import _
 from . import (
-    base85,
     bdiff,
     error,
     mpatch,
@@ -430,7 +429,7 @@ def b85diff(to, tn):
             l = chr(ord('A') + l - 1)
         else:
             l = chr(l - 26 + ord('a') - 1)
-        return '%c%s\n' % (l, base85.b85encode(line, True))
+        return '%c%s\n' % (l, util.b85encode(line, True))
 
     def chunk(text, csize=52):
         l = len(text)
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -74,7 +74,6 @@ import struct
 
 from .i18n import _
 from . import (
-    base85,
     error,
     node,
     parsers,
@@ -744,7 +743,7 @@ def _pushkeyescape(markers):
         currentlen += len(nextdata)
     for idx, part in enumerate(reversed(parts)):
         data = ''.join([_pack('>B', _fm0version)] + part)
-        keys['dump%i' % idx] = base85.b85encode(data)
+        keys['dump%i' % idx] = util.b85encode(data)
     return keys
 
 def listmarkers(repo):
@@ -761,7 +760,7 @@ def pushmarker(repo, key, old, new):
     if old:
         repo.ui.warn(_('unexpected old value for %r') % key)
         return 0
-    data = base85.b85decode(new)
+    data = util.b85decode(new)
     lock = repo.lock()
     try:
         tr = repo.transaction('pushkey: obsolete markers')
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -26,7 +26,6 @@ from .node import (
     short,
 )
 from . import (
-    base85,
     copies,
     diffhelpers,
     encoding,
@@ -1430,7 +1429,7 @@ class binhunk(object):
             else:
                 l = ord(l) - ord('a') + 27
             try:
-                dec.append(base85.b85decode(line[1:])[:l])
+                dec.append(util.b85decode(line[1:])[:l])
             except ValueError as e:
                 raise PatchError(_('could not decode "%s" binary patch: %s')
                                  % (self._fname, str(e)))
diff --git a/mercurial/pvec.py b/mercurial/pvec.py
--- a/mercurial/pvec.py
+++ b/mercurial/pvec.py
@@ -52,7 +52,6 @@ from __future__ import absolute_import
 
 from .node import nullrev
 from . import (
-    base85,
     util,
 )
 
@@ -166,13 +165,13 @@ def ctxpvec(ctx):
                 else:
                     pvc[n] = _mergevec(pvc[p1], pvc[p2], node)
     bs = _join(*pvc[ctx.rev()])
-    return pvec(base85.b85encode(bs))
+    return pvec(util.b85encode(bs))
 
 class pvec(object):
     def __init__(self, hashorctx):
         if isinstance(hashorctx, str):
             self._bs = hashorctx
-            self._depth, self._vec = _split(base85.b85decode(hashorctx))
+            self._depth, self._vec = _split(util.b85decode(hashorctx))
         else:
             self._vec = ctxpvec(hashorctx)
 
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -42,6 +42,7 @@ import warnings
 import zlib
 
 from . import (
+    base85,
     encoding,
     error,
     i18n,
@@ -50,6 +51,9 @@ from . import (
     pycompat,
 )
 
+b85decode = base85.b85decode
+b85encode = base85.b85encode
+
 cookielib = pycompat.cookielib
 empty = pycompat.empty
 httplib = pycompat.httplib


More information about the Mercurial-devel mailing list