[PATCH 2 of 9 RFC] bookmarks: add function for retrieving raw bookmarks values

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


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1471204082 25200
#      Sun Aug 14 12:48:02 2016 -0700
# Node ID d06d34dd880f58ecef32d96baec16508497d5639
# Parent  5aff57cb77481737c73a0acd4885917985bfcf63
bookmarks: add function for retrieving raw bookmarks values

In preparation for adding a binary listkeys wire protocol command,
we need to introduce functions for each pushkey namespace that return
raw, binary values minus any unncessary encoding. We start with the
bookmarks namespace.

listbookmarks() has effectively been copied to listbookmarksraw() and
changed so keys are str/bytes (not localstr) and values are raw node
values instead of hex encoded.

listbookmarks() has been re-implemented in terms of listbookmarksraw().

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -279,27 +279,42 @@ def update(repo, parents, node):
             lock = repo.lock()
             tr = repo.transaction('bookmark')
             marks.recordchange(tr)
             tr.close()
         finally:
             lockmod.release(tr, lock)
     return update
 
-def listbookmarks(repo):
+def listbookmarksraw(repo):
+    """Obtain a dict of bookmarks to be used by the pushkey protocol.
+
+    Keys and values are bytes/binary, not encoded.
+    """
     # We may try to list bookmarks on a repo type that does not
     # support it (e.g., statichttprepository).
     marks = getattr(repo, '_bookmarks', {})
 
     d = {}
     hasnode = repo.changelog.hasnode
     for k, v in marks.iteritems():
         # don't expose local divergent bookmarks
         if hasnode(v) and ('@' not in k or k.endswith('@')):
-            d[k] = hex(v)
+            d[encoding.fromlocal(k)] = v
+
+    return d
+
+def listbookmarks(repo):
+    """Obtain a dict of bookmarks to be used by the pushkey protocol.
+
+    Keys are localstr. Values are hex encoded.
+    """
+    d = {}
+    for k, v in listbookmarksraw(repo).iteritems():
+        d[encoding.tolocal(k)] = hex(v)
     return d
 
 def pushbookmark(repo, key, old, new):
     w = l = tr = None
     try:
         w = repo.wlock()
         l = repo.lock()
         tr = repo.transaction('bookmarks')


More information about the Mercurial-devel mailing list