diff hgext/fastannotate/protocol.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children eef9a2d67051
line wrap: on
line diff
--- a/hgext/fastannotate/protocol.py	Sun Oct 06 09:45:02 2019 -0400
+++ b/hgext/fastannotate/protocol.py	Sun Oct 06 09:48:39 2019 -0400
@@ -25,12 +25,12 @@
 
 def _getmaster(ui):
     """get the mainbranch, and enforce it is set"""
-    master = ui.config('fastannotate', 'mainbranch')
+    master = ui.config(b'fastannotate', b'mainbranch')
     if not master:
         raise error.Abort(
             _(
-                'fastannotate.mainbranch is required '
-                'for both the client and the server'
+                b'fastannotate.mainbranch is required '
+                b'for both the client and the server'
             )
         )
     return master
@@ -41,7 +41,7 @@
 
 def _capabilities(orig, repo, proto):
     result = orig(repo, proto)
-    result.append('getannotate')
+    result.append(b'getannotate')
     return result
 
 
@@ -49,9 +49,9 @@
     # output:
     #   FILE := vfspath + '\0' + str(size) + '\0' + content
     #   OUTPUT := '' | FILE + OUTPUT
-    result = ''
+    result = b''
     buildondemand = repo.ui.configbool(
-        'fastannotate', 'serverbuildondemand', True
+        b'fastannotate', b'serverbuildondemand', True
     )
     with context.annotatecontext(repo, path) as actx:
         if buildondemand:
@@ -80,25 +80,25 @@
             for p in [actx.revmappath, actx.linelogpath]:
                 if not os.path.exists(p):
                     continue
-                with open(p, 'rb') as f:
+                with open(p, b'rb') as f:
                     content = f.read()
-                vfsbaselen = len(repo.vfs.base + '/')
+                vfsbaselen = len(repo.vfs.base + b'/')
                 relpath = p[vfsbaselen:]
-                result += '%s\0%d\0%s' % (relpath, len(content), content)
+                result += b'%s\0%d\0%s' % (relpath, len(content), content)
     return result
 
 
 def _registerwireprotocommand():
-    if 'getannotate' in wireprotov1server.commands:
+    if b'getannotate' in wireprotov1server.commands:
         return
-    wireprotov1server.wireprotocommand('getannotate', 'path lastnode')(
+    wireprotov1server.wireprotocommand(b'getannotate', b'path lastnode')(
         _getannotate
     )
 
 
 def serveruisetup(ui):
     _registerwireprotocommand()
-    extensions.wrapfunction(wireprotov1server, '_capabilities', _capabilities)
+    extensions.wrapfunction(wireprotov1server, b'_capabilities', _capabilities)
 
 
 # client-side
@@ -109,15 +109,15 @@
     i = 0
     l = len(payload) - 1
     state = 0  # 0: vfspath, 1: size
-    vfspath = size = ''
+    vfspath = size = b''
     while i < l:
         ch = payload[i : i + 1]
-        if ch == '\0':
+        if ch == b'\0':
             if state == 1:
                 result[vfspath] = payload[i + 1 : i + 1 + int(size)]
                 i += int(size)
                 state = 0
-                vfspath = size = ''
+                vfspath = size = b''
             elif state == 0:
                 state = 1
         else:
@@ -133,11 +133,11 @@
     class fastannotatepeer(peer.__class__):
         @wireprotov1peer.batchable
         def getannotate(self, path, lastnode=None):
-            if not self.capable('getannotate'):
-                ui.warn(_('remote peer cannot provide annotate cache\n'))
+            if not self.capable(b'getannotate'):
+                ui.warn(_(b'remote peer cannot provide annotate cache\n'))
                 yield None, None
             else:
-                args = {'path': path, 'lastnode': lastnode or ''}
+                args = {b'path': path, b'lastnode': lastnode or b''}
                 f = wireprotov1peer.future()
                 yield args, f
                 yield _parseresponse(f.value)
@@ -150,7 +150,7 @@
     ui = repo.ui
 
     remotepath = ui.expandpath(
-        ui.config('fastannotate', 'remotepath', 'default')
+        ui.config(b'fastannotate', b'remotepath', b'default')
     )
     peer = hg.peer(ui, {}, remotepath)
 
@@ -175,11 +175,12 @@
     ui = repo.ui
     results = []
     with peer.commandexecutor() as batcher:
-        ui.debug('fastannotate: requesting %d files\n' % len(paths))
+        ui.debug(b'fastannotate: requesting %d files\n' % len(paths))
         for p in paths:
             results.append(
                 batcher.callcommand(
-                    'getannotate', {'path': p, 'lastnode': lastnodemap.get(p)}
+                    b'getannotate',
+                    {b'path': p, b'lastnode': lastnodemap.get(p)},
                 )
             )
 
@@ -189,19 +190,21 @@
             r = {util.pconvert(p): v for p, v in r.iteritems()}
             for path in sorted(r):
                 # ignore malicious paths
-                if not path.startswith('fastannotate/') or '/../' in (
-                    path + '/'
+                if not path.startswith(b'fastannotate/') or b'/../' in (
+                    path + b'/'
                 ):
-                    ui.debug('fastannotate: ignored malicious path %s\n' % path)
+                    ui.debug(
+                        b'fastannotate: ignored malicious path %s\n' % path
+                    )
                     continue
                 content = r[path]
                 if ui.debugflag:
                     ui.debug(
-                        'fastannotate: writing %d bytes to %s\n'
+                        b'fastannotate: writing %d bytes to %s\n'
                         % (len(content), path)
                     )
                 repo.vfs.makedirs(os.path.dirname(path))
-                with repo.vfs(path, 'wb') as f:
+                with repo.vfs(path, b'wb') as f:
                     f.write(content)
 
 
@@ -209,7 +212,7 @@
     """return a subset of paths whose history is long and need to fetch linelog
     from the server. works with remotefilelog and non-remotefilelog repos.
     """
-    threshold = repo.ui.configint('fastannotate', 'clientfetchthreshold', 10)
+    threshold = repo.ui.configint(b'fastannotate', b'clientfetchthreshold', 10)
     if threshold <= 0:
         return paths
 
@@ -240,7 +243,7 @@
                     clientfetch(self, needupdatepaths, lastnodemap, peer)
             except Exception as ex:
                 # could be directory not writable or so, not fatal
-                self.ui.debug('fastannotate: prefetch failed: %r\n' % ex)
+                self.ui.debug(b'fastannotate: prefetch failed: %r\n' % ex)
 
     repo.__class__ = fastannotaterepo