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

login
register
mail settings
Submitter Stanislau Hlebik
Date Aug. 25, 2016, 5:59 p.m.
Message ID <c38e4fdad4d5ee218b79.1472147989@dev1918.lla1.facebook.com>
Download mbox | patch
Permalink /patch/16419/
State Accepted
Headers show

Comments

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

Patch

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))
 
+@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