Patchwork [5,of,9,RFC] pushkey: define raw listing functions on each namespace (API)

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 14, 2016, 9:10 p.m.
Message ID <a94e1b0bb3ba0f6b0a3e.1471209004@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16284/
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 1471208975 25200
#      Sun Aug 14 14:09:35 2016 -0700
# Node ID a94e1b0bb3ba0f6b0a3e62d5daece6a5f9ff295c
# Parent  67501b93c9875cc6cdef0e77d2d148a14a5d60a8
pushkey: define raw listing functions on each namespace (API)

In preparation for adding a wire protocol command that sends pushkey
data with minimal encoding, we teach the pushkey namespace registration
APIs about the recently-implemented raw variants to obtain keys.

This will likely break extensions defining custom pushkey namespaces.
Extensions can look at the length of the tuple returned by
pushkey.get() to determine if they need to define a raw listkeys
variant for the Mercurial version they are running on.
Pierre-Yves David - Aug. 17, 2016, 12:02 a.m.
On 08/14/2016 11:10 PM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1471208975 25200
> #      Sun Aug 14 14:09:35 2016 -0700
> # Node ID a94e1b0bb3ba0f6b0a3e62d5daece6a5f9ff295c
> # Parent  67501b93c9875cc6cdef0e77d2d148a14a5d60a8
> pushkey: define raw listing functions on each namespace (API)
>
> In preparation for adding a wire protocol command that sends pushkey
> data with minimal encoding, we teach the pushkey namespace registration
> APIs about the recently-implemented raw variants to obtain keys.
>
> This will likely break extensions defining custom pushkey namespaces.
> Extensions can look at the length of the tuple returned by
> pushkey.get() to determine if they need to define a raw listkeys
> variant for the Mercurial version they are running on.

I would probably not go the root of an extra wireprotocol command around 
pushkey here. Bundle2 have all we need for binary transfer and data are 
better pulled together in one go anyway.

I think we should introduce bundle2 parts for the various piece we need 
as binary. Dedicated part will be able to have finer transfer for them 
anyway.

Patch

diff --git a/mercurial/pushkey.py b/mercurial/pushkey.py
--- a/mercurial/pushkey.py
+++ b/mercurial/pushkey.py
@@ -18,40 +18,46 @@  def _nslist(repo):
     n = {}
     for k in _namespaces:
         n[k] = ""
     if not obsolete.isenabled(repo, obsolete.exchangeopt):
         n.pop('obsolete')
     return n
 
 # Maps pushkey namespace to a tuple defining functions to call for
-# setting and listing entries in the namespace.
+# setting, listing, and listing raw entries in the namespace.
 _namespaces = {
-    'namespaces': (lambda *x: False, _nslist),
-    'bookmarks': (bookmarks.pushbookmark, bookmarks.listbookmarks),
-    'phases': (phases.pushphase, phases.listphases),
-    'obsolete': (obsolete.pushmarker, obsolete.listmarkers),
+    'namespaces': (lambda *x: False, _nslist, _nslist),
+    'bookmarks': (bookmarks.pushbookmark, bookmarks.listbookmarks,
+                  bookmarks.listbookmarksraw),
+    'phases': (phases.pushphase, phases.listphases, phases.listphasesraw),
+    'obsolete': (obsolete.pushmarker, obsolete.listmarkers,
+                 obsolete.listmarkersraw),
 }
 
-def register(namespace, pushkey, listkeys):
-    _namespaces[namespace] = (pushkey, listkeys)
+def register(namespace, pushkey, listkeys, listkeysraw):
+    _namespaces[namespace] = (pushkey, listkeys, listkeysraw)
 
 def _get(namespace):
-    return _namespaces.get(namespace, (lambda *x: False, lambda *x: {}))
+    return _namespaces.get(namespace, (lambda *x: False, lambda *x: {},
+                                       lambda *x: {}))
 
 def push(repo, namespace, key, old, new):
     '''should succeed iff value was old'''
     pk = _get(namespace)[0]
     return pk(repo, key, old, new)
 
 def list(repo, namespace):
     '''return a dict'''
     lk = _get(namespace)[1]
     return lk(repo)
 
+def listraw(repo, namespace):
+    return _get(namespace)[2](repo)
+
 encode = encoding.fromlocal
 
 decode = encoding.tolocal
 
 def encodekeys(keys):
     """encode the content of a pushkey namespace for exchange over the wire"""
     return '\n'.join(['%s\t%s' % (encode(k), encode(v)) for k, v in keys])