base85: proxy through util module
authorYuya Nishihara <yuya@tcha.org>
Wed, 26 Apr 2017 21:56:47 +0900
changeset 37316 4462a981e8df8046e4c49aeb02d501cd192607b0
parent 37315 2d84947cd85d820ff77b2f49ad12b95186497f6e
child 37317 ded48ad5514626a319dc11eb5e198abb471f582a
push id506
push usergszorc@mozilla.com
push dateMon, 08 May 2017 22:36:50 +0000
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.
mercurial/exchange.py
mercurial/mdiff.py
mercurial/obsolete.py
mercurial/patch.py
mercurial/pvec.py
mercurial/util.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -11,17 +11,16 @@ import errno
 import hashlib
 
 from .i18n import _
 from .node import (
     hex,
     nullid,
 )
 from . import (
-    base85,
     bookmarks as bookmod,
     bundle2,
     changegroup,
     discovery,
     error,
     lock as lockmod,
     obsolete,
     phases,
@@ -1504,17 +1503,17 @@ def _pullobsolete(pullop):
     if obsolete.isenabled(pullop.repo, obsolete.exchangeopt):
         pullop.repo.ui.debug('fetching remote obsolete markers\n')
         remoteobs = pullop.remote.listkeys('obsolete')
         if 'dump0' in remoteobs:
             tr = pullop.gettransaction()
             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:
                 pullop.repo.obsstore.add(tr, markers)
             pullop.repo.invalidatevolatilesets()
     return tr
 
 def caps20to10(repo):
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -8,17 +8,16 @@
 from __future__ import absolute_import
 
 import re
 import struct
 import zlib
 
 from .i18n import _
 from . import (
-    base85,
     bdiff,
     error,
     mpatch,
     pycompat,
     util,
 )
 
 patches = mpatch.patches
@@ -425,17 +424,17 @@ def _unidiff(t1, t2, opts=defaultopts):
 def b85diff(to, tn):
     '''print base85-encoded binary diff'''
     def fmtline(line):
         l = len(line)
         if l <= 26:
             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)
         i = 0
         while i < l:
             yield text[i:i + csize]
             i += csize
 
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -69,17 +69,16 @@ comment associated with each format for 
 """
 from __future__ import absolute_import
 
 import errno
 import struct
 
 from .i18n import _
 from . import (
-    base85,
     error,
     node,
     parsers,
     phases,
     util,
 )
 
 _pack = struct.pack
@@ -739,34 +738,34 @@ def _pushkeyescape(markers):
         if (len(nextdata) + currentlen > _maxpayload):
             currentpart = []
             currentlen = 0
             parts.append(currentpart)
         currentpart.append(nextdata)
         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):
     """List markers over pushkey"""
     if not repo.obsstore:
         return {}
     return _pushkeyescape(sorted(repo.obsstore))
 
 def pushmarker(repo, key, old, new):
     """Push markers over pushkey"""
     if not key.startswith('dump'):
         repo.ui.warn(_('unknown key: %r') % key)
         return 0
     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')
         try:
             repo.obsstore.mergemarkers(tr, data)
             tr.close()
             return 1
         finally:
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -21,17 +21,16 @@ import tempfile
 import zlib
 
 from .i18n import _
 from .node import (
     hex,
     short,
 )
 from . import (
-    base85,
     copies,
     diffhelpers,
     encoding,
     error,
     mail,
     mdiff,
     pathutil,
     pycompat,
@@ -1425,17 +1424,17 @@ class binhunk(object):
         line = getline(lr, self.hunk)
         while len(line) > 1:
             l = line[0]
             if l <= 'Z' and l >= 'A':
                 l = ord(l) - ord('A') + 1
             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)))
             line = getline(lr, self.hunk)
         text = zlib.decompress(''.join(dec))
         if len(text) != size:
             raise PatchError(_('"%s" length is %d bytes, should be %d')
                              % (self._fname, len(text), size))
--- a/mercurial/pvec.py
+++ b/mercurial/pvec.py
@@ -47,17 +47,16 @@ Uses:
 - can be used to find a heuristic divergence measure between changesets on
   different branches
 '''
 
 from __future__ import absolute_import
 
 from .node import nullrev
 from . import (
-    base85,
     util,
 )
 
 _size = 448 # 70 chars b85-encoded
 _bytes = _size / 8
 _depthbits = 24
 _depthbytes = _depthbits / 8
 _vecbytes = _bytes - _depthbytes
@@ -161,23 +160,23 @@ def ctxpvec(ctx):
                     # start with a 'random' vector at root
                     pvc[n] = (0, _bin((node * 3)[:_vecbytes]))
                 elif p2 == nullrev:
                     d, v = pvc[p1]
                     pvc[n] = (d + 1, _flipbit(v, node))
                 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)
 
     def __str__(self):
         return self._bs
 
     def __eq__(self, b):
         return self._vec == b._vec and self._depth == b._depth
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -37,24 +37,28 @@ import sys
 import tempfile
 import textwrap
 import time
 import traceback
 import warnings
 import zlib
 
 from . import (
+    base85,
     encoding,
     error,
     i18n,
     osutil,
     parsers,
     pycompat,
 )
 
+b85decode = base85.b85decode
+b85encode = base85.b85encode
+
 cookielib = pycompat.cookielib
 empty = pycompat.empty
 httplib = pycompat.httplib
 httpserver = pycompat.httpserver
 pickle = pycompat.pickle
 queue = pycompat.queue
 socketserver = pycompat.socketserver
 stderr = pycompat.stderr