[PATCH 5 of 8 V5] exchange: getbundle `bookmarks` part generator

Stanislau Hlebik stash at fb.com
Fri Sep 16 07:10:33 EDT 2016


# HG changeset patch
# User Stanislau Hlebik <stash at fb.com>
# Date 1473953140 25200
#      Thu Sep 15 08:25:40 2016 -0700
# Node ID b20ca1e0104fe34775f581295a0d0112dad80cb5
# Parent  7dd18199a5c4e890b634312684a1a05db2fbaac9
exchange: getbundle `bookmarks` part generator

This generator will be used during pull operation.

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 'bookmarks' not in b2caps:
+        raise ValueError(
+            _('bookmarks are requested but client is not capable '
+              'of receiving it'))
+
+    enc = encoding.fromlocal
+    bookmarks = _getbookmarks(repo, **kwargs)
+    encodedbookmarks = '\n'.join(
+        '%s %s' % (enc(bookmark), node)
+        for bookmark, node in bookmarks.items())
+    bundler.newpart('bookmarks', data=encodedbookmarks)
+
 def _getbookmarks(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