Patchwork [6,of,9,RFC] localrepo: support retrieving raw pushkeys

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 14, 2016, 9:10 p.m.
Message ID <1fe812eb8b9e79d1182c.1471209005@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16285/
State Changes Requested
Headers show

Comments

Gregory Szorc - Aug. 14, 2016, 9:10 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1471207051 25200
#      Sun Aug 14 13:37:31 2016 -0700
# Node ID 1fe812eb8b9e79d1182c4a6593e7ce8fa2938264
# Parent  a94e1b0bb3ba0f6b0a3e62d5daece6a5f9ff295c
localrepo: support retrieving raw pushkeys

Now that we have pushkey support for retrieving raw values,
wire support for calling it into repo instances.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -200,18 +200,18 @@  class localpeer(peer.peerrepository):
         return self._repo.lock()
 
     def addchangegroup(self, cg, source, url):
         return cg.apply(self._repo, source, url)
 
     def pushkey(self, namespace, key, old, new):
         return self._repo.pushkey(namespace, key, old, new)
 
-    def listkeys(self, namespace):
-        return self._repo.listkeys(namespace)
+    def listkeys(self, namespace, raw=False):
+        return self._repo.listkeys(namespace, raw=raw)
 
     def debugwireargs(self, one, two, three=None, four=None, five=None):
         '''used to test argument passing over the wire'''
         return "%s %s %s %s %s" % (one, two, three, four, five)
 
 class locallegacypeer(localpeer):
     '''peer extension which implements legacy methods too; used for tests with
     restricted capabilities'''
@@ -1902,21 +1902,28 @@  class localrepository(object):
         self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
         ret = pushkey.push(self, namespace, key, old, new)
         def runhook():
             self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
                       ret=ret)
         self._afterlock(runhook)
         return ret
 
-    def listkeys(self, namespace):
+    def listkeys(self, namespace, raw=False):
         self.hook('prelistkeys', throw=True, namespace=namespace)
         self.ui.debug('listing keys for "%s"\n' % namespace)
         values = pushkey.list(self, namespace)
         self.hook('listkeys', namespace=namespace, values=values)
+
+        # Hooks above always receive the non-raw values for BC reasons.
+        # Unfortunately for performance, this means we have to obtain
+        # both the raw and non-raw forms if raw data is requested.
+        if raw:
+            values = pushkey.listraw(self, namespace)
+
         return values
 
     def debugwireargs(self, one, two, three=None, four=None, five=None):
         '''used to test argument passing over the wire'''
         return "%s %s %s %s %s" % (one, two, three, four, five)
 
     def savecommitmessage(self, text):
         fp = self.vfs('last-message.txt', 'wb')
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -12,19 +12,19 @@ 
   > }
   $ getid() {
   >    hg log -T "{node}\n" --hidden -r "desc('$1')"
   > }
 
   $ cat > debugkeys.py <<EOF
   > def reposetup(ui, repo):
   >     class debugkeysrepo(repo.__class__):
-  >         def listkeys(self, namespace):
+  >         def listkeys(self, namespace, raw=False):
   >             ui.write('listkeys %s\n' % (namespace,))
-  >             return super(debugkeysrepo, self).listkeys(namespace)
+  >             return super(debugkeysrepo, self).listkeys(namespace, raw=raw)
   > 
   >     if repo.local():
   >         repo.__class__ = debugkeysrepo
   > EOF
 
   $ hg init tmpa
   $ cd tmpa
   $ mkcommit kill_me