Patchwork [5,of,5] push: add bookmarks to the unified bundle2 push

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 18, 2014, 11:48 p.m.
Message ID <e814ea2950f70af18dba.1408405683@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5490/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 18, 2014, 11:48 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1408154622 25200
#      Fri Aug 15 19:03:42 2014 -0700
# Node ID e814ea2950f70af18dba3f69e15aece2d39f4814
# Parent  09758826d5987cad7134be10f64a909abe407eec
push: add bookmarks to the unified bundle2 push

We use the `pushkey` part to exchange bookmark updates within the unified
bundle2 push. Note that this only apply on update (move a bookmark known on both
side) since bookmark export (creation of a new bookmark on remote) are apparently
done outside of the _push function.
Augie Fackler - Aug. 19, 2014, 12:08 a.m.
On Mon, Aug 18, 2014 at 04:48:03PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1408154622 25200
> #      Fri Aug 15 19:03:42 2014 -0700
> # Node ID e814ea2950f70af18dba3f69e15aece2d39f4814
> # Parent  09758826d5987cad7134be10f64a909abe407eec
> push: add bookmarks to the unified bundle2 push
>
> We use the `pushkey` part to exchange bookmark updates within the unified
> bundle2 push. Note that this only apply on update (move a bookmark known on both
> side) since bookmark export (creation of a new bookmark on remote) are apparently
> done outside of the _push function.

Seems like a good start. Can we fix the creation of bookmarks problem?

What's the right thing to do about deletions?

In any case, queued (but do discuss these problems, and/or file
tracking bugs in bz so we don't forget).

>
> diff --git a/mercurial/exchange.py b/mercurial/exchange.py
> --- a/mercurial/exchange.py
> +++ b/mercurial/exchange.py
> @@ -420,10 +420,44 @@ def _pushb2phases(pushop, bundler):
>                  msg = _('updating %s to public failed!\n') % node
>              if msg is not None:
>                  pushop.ui.warn(msg)
>      return handlereply
>
> +@b2partsgenerator('bookmarks')
> +def _pushb2bookmarks(pushop, bundler):
> +    """handle phase push through bundle2"""
> +    if 'bookmarks' in pushop.stepsdone:
> +        return
> +    b2caps = bundle2.bundle2caps(pushop.remote)
> +    if 'b2x:pushkey' not in b2caps:
> +        return
> +    pushop.stepsdone.add('bookmarks')
> +    part2book = []
> +    enc = pushkey.encode
> +    for book, old, new in pushop.outbookmarks:
> +        part = bundler.newpart('b2x:pushkey')
> +        part.addparam('namespace', enc('bookmarks'))
> +        part.addparam('key', enc(book))
> +        part.addparam('old', enc(old))
> +        part.addparam('new', enc(new))
> +        part2book.append((part.id, book))
> +    def handlereply(op):
> +        for partid, book in part2book:
> +            partrep = op.records.getreplies(partid)
> +            results = partrep['pushkey']
> +            assert len(results) <= 1
> +            if not results:
> +                pushop.ui.warn(_('server ignored bookmark %s update\n') % book)
> +            else:
> +                ret = int(results[0]['return'])
> +                if ret:
> +                    pushop.ui.status(_("updating bookmark %s\n") % book)
> +                else:
> +                    pushop.ui.warn(_('updating bookmark %s failed!\n') % book)
> +    return handlereply
> +
> +
>  def _pushbundle2(pushop):
>      """push data to the remote using bundle2
>
>      The only currently supported type of data is changegroup but this will
>      evolve in the future."""
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Pierre-Yves David - Aug. 19, 2014, 12:13 a.m.
On 08/18/2014 05:08 PM, Augie Fackler wrote:
> On Mon, Aug 18, 2014 at 04:48:03PM -0700, Pierre-Yves David wrote:
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david@fb.com>
>> # Date 1408154622 25200
>> #      Fri Aug 15 19:03:42 2014 -0700
>> # Node ID e814ea2950f70af18dba3f69e15aece2d39f4814
>> # Parent  09758826d5987cad7134be10f64a909abe407eec
>> push: add bookmarks to the unified bundle2 push
>>
>> We use the `pushkey` part to exchange bookmark updates within the unified
>> bundle2 push. Note that this only apply on update (move a bookmark known on both
>> side) since bookmark export (creation of a new bookmark on remote) are apparently
>> done outside of the _push function.
>
> Seems like a good start. Can we fix the creation of bookmarks problem?
>
> What's the right thing to do about deletions?
>
> In any case, queued (but do discuss these problems, and/or file
> tracking bugs in bz so we don't forget).

I'm about to move bookmark within the transaction and gather all the 
lost sheep in a single place. I'm not sure a ticket is necessary.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -420,10 +420,44 @@  def _pushb2phases(pushop, bundler):
                 msg = _('updating %s to public failed!\n') % node
             if msg is not None:
                 pushop.ui.warn(msg)
     return handlereply
 
+@b2partsgenerator('bookmarks')
+def _pushb2bookmarks(pushop, bundler):
+    """handle phase push through bundle2"""
+    if 'bookmarks' in pushop.stepsdone:
+        return
+    b2caps = bundle2.bundle2caps(pushop.remote)
+    if 'b2x:pushkey' not in b2caps:
+        return
+    pushop.stepsdone.add('bookmarks')
+    part2book = []
+    enc = pushkey.encode
+    for book, old, new in pushop.outbookmarks:
+        part = bundler.newpart('b2x:pushkey')
+        part.addparam('namespace', enc('bookmarks'))
+        part.addparam('key', enc(book))
+        part.addparam('old', enc(old))
+        part.addparam('new', enc(new))
+        part2book.append((part.id, book))
+    def handlereply(op):
+        for partid, book in part2book:
+            partrep = op.records.getreplies(partid)
+            results = partrep['pushkey']
+            assert len(results) <= 1
+            if not results:
+                pushop.ui.warn(_('server ignored bookmark %s update\n') % book)
+            else:
+                ret = int(results[0]['return'])
+                if ret:
+                    pushop.ui.status(_("updating bookmark %s\n") % book)
+                else:
+                    pushop.ui.warn(_('updating bookmark %s failed!\n') % book)
+    return handlereply
+
+
 def _pushbundle2(pushop):
     """push data to the remote using bundle2
 
     The only currently supported type of data is changegroup but this will
     evolve in the future."""