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

Gregory Szorc gregory.szorc at gmail.com
Sun Aug 14 17:10:04 EDT 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at 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.

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])
 


More information about the Mercurial-devel mailing list