Patchwork [7,of,9,V6] exchange: getbundle `bookmarks` part generator

login
register
mail settings
Submitter Stanislau Hlebik
Date Oct. 11, 2016, 4:25 p.m.
Message ID <48e5db9c751c1eca1901.1476203149@dev1918.lla1.facebook.com>
Download mbox | patch
Permalink /patch/17038/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Stanislau Hlebik - Oct. 11, 2016, 4:25 p.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1476195835 25200
#      Tue Oct 11 07:23:55 2016 -0700
# Node ID 48e5db9c751c1eca19019bbc24de43f7cb3368e7
# Parent  b9e71247c1b68ce1fac7dd69cf26d106f88f9372
exchange: getbundle `bookmarks` part generator

This generator will be used during pull operation.
Pierre-Yves David - Oct. 14, 2016, 1:28 a.m.
On 10/11/2016 06:25 PM, Stanislau Hlebik wrote:
> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1476195835 25200
> #      Tue Oct 11 07:23:55 2016 -0700
> # Node ID 48e5db9c751c1eca19019bbc24de43f7cb3368e7
> # Parent  b9e71247c1b68ce1fac7dd69cf26d106f88f9372
> exchange: getbundle `bookmarks` part generator
>
> This generator will be used during pull operation.

The change itself looks good to me. (you might want to add some details 
about how the creation of the part is triggered from the client if you 
want to make it easier to review, but that's perfectly fine as is).

Now that we have internal documentations, we will want to introduce a 
section about these bundle2 part and related bookmarkes exchange (and 
format).

The documentation lives in mercurial/help/internals/

> diff --git a/mercurial/exchange.py b/mercurial/exchange.py
> --- a/mercurial/exchange.py
> +++ b/mercurial/exchange.py
> @@ -1672,6 +1672,21 @@
>      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 'bookmarks' not in b2caps:
> +        raise ValueError(
> +            _('bookmarks are requested but client is not capable '
> +              'of receiving it'))
> +
> +    bookmarks = _getbookmarks(repo, **kwargs)
> +    encodedbookmarks = bookmod.encodebookmarks(bookmarks)
> +    bundler.newpart('bookmarks', data=encodedbookmarks)
> +
>  def _getbookmarks(repo, **kwargs):
>      """Returns list of bookmarks.
>
> diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
> --- a/mercurial/wireproto.py
> +++ b/mercurial/wireproto.py
> @@ -220,7 +220,8 @@
>               'bundlecaps': 'scsv',
>               'listkeys': 'csv',
>               'cg': 'boolean',
> -             'cbattempted': 'boolean'}
> +             'cbattempted': 'boolean',
> +             'bookmarks': 'boolean'}

If you have the chance, put the closing '}' on its own line and use a 
trailing comma on the line you add. This will make the next guy life easier.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1672,6 +1672,21 @@ 
     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 'bookmarks' not in b2caps:
+        raise ValueError(
+            _('bookmarks are requested but client is not capable '
+              'of receiving it'))
+
+    bookmarks = _getbookmarks(repo, **kwargs)
+    encodedbookmarks = bookmod.encodebookmarks(bookmarks)
+    bundler.newpart('bookmarks', data=encodedbookmarks)
+
 def _getbookmarks(repo, **kwargs):
     """Returns list of bookmarks.
 
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -220,7 +220,8 @@ 
              'bundlecaps': 'scsv',
              'listkeys': 'csv',
              'cg': 'boolean',
-             'cbattempted': 'boolean'}
+             'cbattempted': 'boolean',
+             'bookmarks': 'boolean'}
 
 # client side