# HG changeset patch
# User Boris Feld <boris.f...@octobus.net>
# Date 1508236693 -7200
#      Tue Oct 17 12:38:13 2017 +0200
# Node ID 9a8c55d83b3601a41f0d406f80de2f245bbb6c83
# Parent  e634131ba39fa08d292675ca73a6c0cf8cb2588b
# EXP-Topic b2.bookmarks
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 
9a8c55d83b36
bookmark: use the 'bookmarks' bundle2 part to push bookmark update (issue5165)

We use the new binary parts we introduced earlier to exchange bookmark. The
payload is a bit more compact since we use binary and the length of bookmarks
is no longer constrained to 255.

.. fix:: Issue 5165

   Bookmark, whose name is longer than 255, can again be exchanged again
   between 4.4+ client and servers.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -896,9 +896,45 @@ def _pushb2bookmarks(pushop, bundler):
     if 'bookmarks' in pushop.stepsdone:
         return
     b2caps = bundle2.bundle2caps(pushop.remote)
-    if 'pushkey' in b2caps:
+
+    legacy = pushop.repo.ui.configlist('devel', 'legacy.exchange')
+    legacybooks = 'bookmarks' in legacy
+
+    if not legacybooks and 'bookmarks' in b2caps:
+        return _pushb2bookmarkspart(pushop, bundler)
+    elif 'pushkey' in b2caps:
         return _pushb2bookmarkspushkey(pushop, bundler)
 
+def _bmaction(old, new):
+    """small utility for bookmark pushing"""
+    if not old:
+        return 'export'
+    elif not new:
+        return 'delete'
+    return 'update'
+
+def _pushb2bookmarkspart(pushop, bundler):
+    pushop.stepsdone.add('bookmarks')
+    if not pushop.outbookmarks:
+        return
+
+    allactions = []
+    data = []
+    for book, old, new in pushop.outbookmarks:
+        new = bin(new)
+        data.append((book, new))
+        allactions.append((book, _bmaction(old, new)))
+    checkdata = bookmod.binaryencode(data)
+    bundler.newpart('bookmarks', data=checkdata)
+
+    def handlereply(op):
+        ui = pushop.ui
+        # if success
+        for book, action in allactions:
+            ui.status(bookmsgmap[action][0] % book)
+
+    return handlereply
+
 def _pushb2bookmarkspushkey(pushop, bundler):
     pushop.stepsdone.add('bookmarks')
     part2book = []
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -1,4 +1,12 @@
 #testcases b2-pushkey b2-binary
+
+#if b2-pushkey
+  $ cat << EOF >> $HGRCPATH
+  > [devel]
+  > legacy.exchange=bookmarks
+  > EOF
+#endif
+
 #require serve
 
   $ cat << EOF >> $HGRCPATH
@@ -250,10 +258,11 @@ delete a remote bookmark
   bundle2-output: header chunk size: 19
   bundle2-output: payload chunk size: 48
   bundle2-output: closing payload chunk
-  bundle2-output: bundle part: "pushkey"
-  bundle2-output-part: "pushkey" (params: 4 mandatory) empty payload
-  bundle2-output: part 3: "PUSHKEY"
-  bundle2-output: header chunk size: 90
+  bundle2-output: bundle part: "bookmarks"
+  bundle2-output-part: "bookmarks" 23 bytes payload
+  bundle2-output: part 3: "BOOKMARKS"
+  bundle2-output: header chunk size: 16
+  bundle2-output: payload chunk size: 23
   bundle2-output: closing payload chunk
   bundle2-output: end of bundle
   bundle2-input: start processing of HG20 stream
@@ -287,40 +296,29 @@ delete a remote bookmark
   bundle2-input: payload chunk size: 48
   bundle2-input: payload chunk size: 0
   bundle2-input-part: total payload size 48
-  bundle2-input: part header size: 90
-  bundle2-input: part type: "PUSHKEY"
+  bundle2-input: part header size: 16
+  bundle2-input: part type: "BOOKMARKS"
   bundle2-input: part id: "3"
-  bundle2-input: part parameters: 4
-  bundle2-input: found a handler for part pushkey
-  bundle2-input-part: "pushkey" (params: 4 mandatory) supported
-  pushing key for "bookmarks:W"
+  bundle2-input: part parameters: 0
+  bundle2-input: found a handler for part bookmarks
+  bundle2-input-part: "bookmarks" supported
+  bundle2-input: payload chunk size: 23
   bundle2-input: payload chunk size: 0
+  bundle2-input-part: total payload size 23
   bundle2-input: part header size: 0
   bundle2-input: end of bundle2 stream
   bundle2-input-bundle: 3 parts total
   running hook txnclose-bookmark.test: sh $TESTTMP/hook.sh
   test-hook-bookmark: W:  0000000000000000000000000000000000000000 -> 
-  bundle2-output-bundle: "HG20", 1 parts total
+  bundle2-output-bundle: "HG20", 0 parts total
   bundle2-output: start emission of HG20 stream
   bundle2-output: bundle parameter: 
   bundle2-output: start of parts
-  bundle2-output: bundle part: "reply:pushkey"
-  bundle2-output-part: "reply:pushkey" (params: 0 advisory) empty payload
-  bundle2-output: part 0: "REPLY:PUSHKEY"
-  bundle2-output: header chunk size: 43
-  bundle2-output: closing payload chunk
   bundle2-output: end of bundle
   bundle2-input: start processing of HG20 stream
   bundle2-input: reading bundle2 stream parameters
   bundle2-input-bundle: no-transaction
   bundle2-input: start extraction of bundle2 parts
-  bundle2-input: part header size: 43
-  bundle2-input: part type: "REPLY:PUSHKEY"
-  bundle2-input: part id: "0"
-  bundle2-input: part parameters: 2
-  bundle2-input: found a handler for part reply:pushkey
-  bundle2-input-part: "reply:pushkey" (params: 0 advisory) supported
-  bundle2-input: payload chunk size: 0
   bundle2-input: part header size: 0
   bundle2-input: end of bundle2 stream
   bundle2-input-bundle: 0 parts total
@@ -1088,8 +1086,7 @@ Local push
   pushing to $TESTTMP/issue4455-dest (glob)
   searching for changes
   no changes found
-  pushkey-abort: prepushkey hook exited with status 1
-  abort: exporting bookmark @ failed!
+  abort: prepushkey hook exited with status 1
   [255]
 
 #endif
@@ -1128,8 +1125,8 @@ Using ssh
   pushing to ssh://user@dummy/issue4455-dest
   searching for changes
   no changes found
-  remote: pushkey-abort: prepushkey hook exited with status 1
-  abort: exporting bookmark @ failed!
+  remote: prepushkey hook exited with status 1
+  abort: push failed on remote
   [255]
 
 #endif
@@ -1168,8 +1165,8 @@ Using http
   pushing to ssh://user@dummy/issue4455-dest
   searching for changes
   no changes found
-  remote: pushkey-abort: prepushkey hook exited with status 1
-  abort: exporting bookmark @ failed!
+  remote: prepushkey hook exited with status 1
+  abort: push failed on remote
   [255]
 
 #endif
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
@@ -253,9 +253,6 @@ push
   remote: added 1 changesets with 0 changes to 0 files (-1 heads)
   remote: 1 new obsolescence markers
   remote: pre-close-tip:eea13746799a public book_eea1
-  remote: pushkey: lock state after "bookmarks"
-  remote: lock:  free
-  remote: wlock: free
   remote: postclose-tip:eea13746799a public book_eea1
   remote: txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 
HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 
HG_NODE=eea13746799a9e0bfd88f29d3c2e9dc9389f524f 
HG_NODE_LAST=eea13746799a9e0bfd88f29d3c2e9dc9389f524f HG_PHASES_MOVED=1 
HG_SOURCE=push HG_TXNID=TXN:$ID$ HG_TXNNAME=push HG_URL=file:$TESTTMP/other
   updating bookmark book_eea1
@@ -339,9 +336,6 @@ push over ssh
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
   remote: pre-close-tip:5fddd98957c8 draft book_5fdd
-  remote: pushkey: lock state after "bookmarks"
-  remote: lock:  free
-  remote: wlock: free
   remote: postclose-tip:5fddd98957c8 draft book_5fdd
   remote: txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 
HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 
HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b 
HG_NODE_LAST=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve 
HG_TXNID=TXN:$ID$ HG_TXNNAME=serve HG_URL=remote:ssh:$LOCALIP
   updating bookmark book_5fdd
@@ -390,9 +384,6 @@ push over http
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
   remote: pre-close-tip:32af7686d403 public book_32af
-  remote: pushkey: lock state after "bookmarks"
-  remote: lock:  free
-  remote: wlock: free
   remote: postclose-tip:32af7686d403 public book_32af
   remote: txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 
HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 
HG_NODE=32af7686d403cf45b5d95f2d70cebea587ac806a 
HG_NODE_LAST=32af7686d403cf45b5d95f2d70cebea587ac806a HG_PHASES_MOVED=1 
HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_TXNNAME=serve HG_URL=remote:http:$LOCALIP: 
(glob)
   updating bookmark book_32af
diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -244,7 +244,6 @@ pushkey hook
   no changes found
   pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen 
HG_TXNID=TXN:$ID$ HG_TXNNAME=push
   pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_HOOKNAME=pretxnclose 
HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_SOURCE=push HG_TXNID=TXN:$ID$ 
HG_TXNNAME=push HG_URL=file:$TESTTMP/a
-  pushkey hook: HG_HOOKNAME=pushkey HG_HOOKTYPE=pushkey HG_KEY=foo 
HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000 HG_RET=1
   txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_HOOKNAME=txnclose 
HG_HOOKTYPE=txnclose HG_SOURCE=push HG_TXNID=TXN:$ID$ HG_TXNNAME=push 
HG_URL=file:$TESTTMP/a
   exporting bookmark foo
   [1]
@@ -281,9 +280,8 @@ test that prepushkey can prevent incomin
   listkeys hook: HG_HOOKNAME=listkeys HG_HOOKTYPE=listkeys 
HG_NAMESPACE=bookmarks HG_VALUES={'bar': 
'0000000000000000000000000000000000000000', 'foo': 
'0000000000000000000000000000000000000000'}
   no changes found
   pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen 
HG_TXNID=TXN:$ID$ HG_TXNNAME=push
-  prepushkey.forbid hook: HG_BUNDLE2=1 HG_HOOKNAME=prepushkey 
HG_HOOKTYPE=prepushkey HG_KEY=baz HG_NAMESPACE=bookmarks 
HG_NEW=0000000000000000000000000000000000000000 HG_SOURCE=push 
HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
-  pushkey-abort: prepushkey hook exited with status 1
-  abort: exporting bookmark baz failed!
+  prepushkey.forbid hook: HG_BUNDLE2=1 HG_HOOKNAME=prepushkey 
HG_HOOKTYPE=prepushkey HG_KEY=baz HG_NAMESPACE=bookmark 
HG_NEW=0000000000000000000000000000000000000000 HG_PUSHKEYCOMPAT=1 
HG_SOURCE=push HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
+  abort: prepushkey hook exited with status 1
   [255]
   $ cd ../a
 
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to