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

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 14, 2016, 9:10 p.m.
Message ID <d06d34dd880f58ecef32.1471209001@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16280/
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 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().

Patch

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