[PATCH 2 of 7 V4] exchange: add `bookmarks` part generator

Stanislau Hlebik stash at fb.com
Sun Sep 4 18:46:54 EDT 2016


# HG changeset patch
# User Stanislau Hlebik <stash at fb.com>
# Date 1473012054 25200
#      Sun Sep 04 11:00:54 2016 -0700
# Node ID f3bc1662dbce19de1f51c4da519238dbe98c1c95
# Parent  6e9d1438a270ba02cd06590efd959039b0fae566
exchange: add `bookmarks` part generator

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1252,6 +1252,7 @@
                 'digests': tuple(sorted(util.DIGESTS.keys())),
                 'remote-changegroup': ('http', 'https'),
                 'hgtagsfnodes': (),
+                'bookmarks': (),
                }
 
 def getrepocaps(repo, allowpushback=False):
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -21,6 +21,7 @@
     bundle2,
     changegroup,
     discovery,
+    encoding,
     error,
     lock as lockmod,
     obsolete,
@@ -1671,6 +1672,24 @@
     if chunks:
         bundler.newpart('hgtagsfnodes', data=''.join(chunks))
 
+ at getbundle2partsgenerator('bookmarks')
+def _getbundlebookmarkspart(bundler, repo, source, bundlecaps=None,
+                            b2caps=None, heads=None, common=None,
+                            **kwargs):
+    if not kwargs.get('bookmarks'):
+        return
+    if kwargs.get('bookmarks') and 'bookmarks' not in b2caps:
+        raise ValueError(
+            _('bookmarks are requested but client is not capable '
+              'of receiving it'))
+
+    enc = encoding.fromlocal
+    bookmarks = _get_bookmarks(repo, kwargs)
+    encodedbookmarks = '\n'.join(
+        '%s %s' % (enc(bookmark), enc(node))
+        for bookmark, node in bookmarks.items())
+    bundler.newpart('bookmarks', data=encodedbookmarks)
+
 def _get_bookmarks(repo, kwargs):
     return repo.listkeys(namespace='bookmarks')
 
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -219,7 +219,8 @@
              'bundlecaps': 'scsv',
              'listkeys': 'csv',
              'cg': 'boolean',
-             'cbattempted': 'boolean'}
+             'cbattempted': 'boolean',
+             'bookmarks': 'boolean'}
 
 # client side
 


More information about the Mercurial-devel mailing list