Patchwork [3,of,3,V2] getbundle: add `bookmarkpatterns` parameter

login
register
mail settings
Submitter Stanislau Hlebik
Date Aug. 23, 2016, 10:22 a.m.
Message ID <d797649380c3e9dbf18d.1471947764@dev1918.lla1.facebook.com>
Download mbox | patch
Permalink /patch/16393/
State Accepted
Headers show

Comments

Stanislau Hlebik - Aug. 23, 2016, 10:22 a.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1471947390 25200
#      Tue Aug 23 03:16:30 2016 -0700
# Node ID d797649380c3e9dbf18d056ac52345a0fc31ddc1
# Parent  6cad044c2ea002d3a4c1e45666e89c99b7fbdd0f
getbundle: add `bookmarkpatterns` parameter
Pierre-Yves David - Aug. 24, 2016, 10:41 p.m.
On 08/23/2016 12:22 PM, Stanislau Hlebik wrote:
> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1471947390 25200
> #      Tue Aug 23 03:16:30 2016 -0700
> # Node ID d797649380c3e9dbf18d056ac52345a0fc31ddc1
> # Parent  6cad044c2ea002d3a4c1e45666e89c99b7fbdd0f
> getbundle: add `bookmarkpatterns` parameter

The next step here should be to actually use the new code instead of 
making it more complex.

There is code dedicated to requesting and processing bookmark in 
exchange.py. This code needs to be updated to (when possible) use the 
new 'bookmarks' argument and part instead of the listkey one. This would 
also get the new code run through the tests without having to build 
specialized command.

In addition, I don't think the 'bookmarkspattern' belong to core yet. 
(yes it contradict some of my previous messages, but things are getting 
clearer now that we have piece of implementation visible).
The only user for it lives in an external extension, so the extra 
argument should live there. Just make sure the part generation is 
flexible enough to be wrapped by the extensions (this will be something 
around the listing of bookmarks).
I know the bundle2/exchange code is flexible enough for this kind of 
things as I'm doing so in a couple of extensions already.

To summaries I would like to see a V3 with.

- a new 'bookmark' part an appropriate minimal encoding (maybe reuse the 
on disk format?),
- a 'bookmarks' argument to get bundle to request it,
- a capability advertising it,
- the exchange code updated to use it when available,
- no change to the listkey protocol,
- no introduction of bookmarkpatterns for now,

Cheers,

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1657,7 +1657,8 @@ 
     if not (kwargs.get('bookmarks') and 'bookmarks' in b2caps):
         return
 
-    bookmarks = repo.listkeys(namespace='bookmarks')
+    patterns = kwargs.get('bookmarkpatterns', None)
+    bookmarks = repo.listkeys(namespace='bookmarks', patterns=patterns)
     encodedbookmarks = pushkey.encodekeys(bookmarks.items())
     bundler.newpart('bookmarks', data=encodedbookmarks)
 
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -205,7 +205,8 @@ 
              'listkeys': 'csv',
              'cg': 'boolean',
              'cbattempted': 'boolean',
-             'bookmarks': 'boolean'}
+             'bookmarks': 'boolean',
+             'bookmarkpatterns': 'csv'}
 
 # client side
 
diff --git a/tests/test-bundle2-exchange.t b/tests/test-bundle2-exchange.t
--- a/tests/test-bundle2-exchange.t
+++ b/tests/test-bundle2-exchange.t
@@ -1114,3 +1114,31 @@ 
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
+
+  $ cd ..
+  $ cat > debuggetbundlebookmarks.py << EOF
+  > from mercurial import bundle2, cmdutil, exchange, hg
+  > cmdtable = {}
+  > command = cmdutil.command(cmdtable)
+  > @command('debuggetbundlebookmarks', [
+  >   ('', 'bookmarkpatterns', [], 'Patterns of bookmark'),
+  > ],)
+  > def debuggetbundlebookmarks(ui, repo, bookmarkpatterns):
+  >   source, branches = hg.parseurl(ui.expandpath('default'))
+  >   other = hg.peer(repo, {}, source)
+  >   bundle = other.getbundle(
+  >       'debuggetbundle', bundlecaps=exchange.caps20to10(repo),
+  >       bookmarks=True, cg=False, bookmarkpatterns=bookmarkpatterns)
+  >   op = bundle2.processbundle(repo, bundle)
+  >   ui.status('Finished %s\n' % (sorted(op.records['bookmarks'][0].items()), ))
+  > EOF
+  $ cd other
+  $ hg --config extensions.debuggetbundlebookmarks=../debuggetbundlebookmarks.py debuggetbundlebookmarks
+  obsolete feature not enabled but 7 markers found!
+  Finished [('book_02de', '02de42196ebee42ef284b6780a87cdc96e8eaab6'), ('book_32af', '32af7686d403cf45b5d95f2d70cebea587ac806a'), ('book_42cc', '42ccdea3bb16d28e1848c95fe2e44c000f3f21b1'), ('book_5fdd', '5fddd98957c8a54a4d436dfe1da9d87f21a1b97b'), ('book_eea1', 'eea13746799a9e0bfd88f29d3c2e9dc9389f524f')]
+  $ hg --config extensions.debuggetbundlebookmarks=../debuggetbundlebookmarks.py debuggetbundlebookmarks --bookmarkpatterns 're:.*5fdd'
+  obsolete feature not enabled but 7 markers found!
+  Finished [('book_5fdd', '5fddd98957c8a54a4d436dfe1da9d87f21a1b97b')]
+  $ hg --config extensions.debuggetbundlebookmarks=../debuggetbundlebookmarks.py debuggetbundlebookmarks --bookmarkpatterns 're:.*5fdd' --bookmarkpatterns 're:.*eea1'
+  obsolete feature not enabled but 7 markers found!
+  Finished [('book_5fdd', '5fddd98957c8a54a4d436dfe1da9d87f21a1b97b'), ('book_eea1', 'eea13746799a9e0bfd88f29d3c2e9dc9389f524f')]