Submitter | Stanislau Hlebik |
---|---|
Date | Sept. 4, 2016, 10:46 p.m. |
Message ID | <f3bc1662dbce19de1f51.1473029214@dev1918.lla1.facebook.com> |
Download | mbox | patch |
Permalink | /patch/16543/ |
State | Accepted |
Headers | show |
Comments
On 09/05/2016 12:46 AM, Stanislau Hlebik wrote: > # HG changeset patch > # User Stanislau Hlebik <stash@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)) > > +@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: The second check for kwargs.get('bookmarks') seems to be redundant. > + 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)) Encoding nodes seems a bit strange? Why are you doing this? > + for bookmark, node in bookmarks.items()) > + bundler.newpart('bookmarks', data=encodedbookmarks) If we forsee the bookmark part to be huge we could turn the data generation into a generator instead. > 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'}
Patch
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)) +@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