[PATCH 2 of 4 V3] exchange: add `bookmarks` part generator

Stanislau Hlebik stash at fb.com
Thu Aug 25 13:59:49 EDT 2016


# HG changeset patch
# User Stanislau Hlebik <stash at fb.com>
# Date 1472125520 25200
#      Thu Aug 25 04:45:20 2016 -0700
# Node ID c38e4fdad4d5ee218b795a9908665484ed996999
# Parent  daecb4cb68a6abaf8059afee18d95481043ff2f6
exchange: add `bookmarks` part generator

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1249,6 +1249,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
@@ -1650,6 +1650,22 @@
     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'))
+
+    bookmarks = _get_bookmarks(repo, kwargs)
+    encodedbookmarks = '\n'.join(
+        '%s %s' % (bookmark, 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
@@ -204,7 +204,8 @@
              'bundlecaps': 'scsv',
              'listkeys': 'csv',
              'cg': 'boolean',
-             'cbattempted': 'boolean'}
+             'cbattempted': 'boolean',
+             'bookmarks': 'boolean'}
 
 # client side
 


More information about the Mercurial-devel mailing list