[PATCH 4 of 7 V4] exchange: add `pushbookmarks` part generator
Stanislau Hlebik
stash at fb.com
Sun Sep 4 18:46:56 EDT 2016
# HG changeset patch
# User Stanislau Hlebik <stash at fb.com>
# Date 1473022588 25200
# Sun Sep 04 13:56:28 2016 -0700
# Node ID db526b94eeb678879c2faceb40c64aebbe1054af
# Parent 70a86f2bd0e7684eda82310dc9024b346f59dbf6
exchange: add `pushbookmarks` part generator
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -806,6 +806,50 @@
markers = sorted(pushop.outobsmarkers)
buildobsmarkerspart(bundler, markers)
+ at b2partsgenerator('pushbookmarks')
+def _pushb2bookmarksnew(pushop, bundler):
+ if 'bookmarks' in pushop.stepsdone:
+ return
+ b2caps = bundle2.bundle2caps(pushop.remote)
+ if 'pushbookmarks' not in b2caps:
+ return
+ pushop.stepsdone.add('bookmarks')
+ if not pushop.outbookmarks:
+ return
+ booktoaction = {}
+ bookmarksdata = []
+ enc = encoding.fromlocal
+ for book, old, new in pushop.outbookmarks:
+ action = 'update'
+ if not old:
+ action = 'export'
+ elif not new:
+ action = 'delete'
+ booktoaction[book] = action
+ bookmarksdata.append('%s %s %s' % (enc(book), enc(old), enc(new)))
+ part = bundler.newpart('pushbookmarks', data='\n'.join(bookmarksdata))
+
+ def handlereply(op):
+ ui = pushop.ui
+ partrep = op.records.getreplies(part.id)
+ replies = {}
+ for reply in partrep['pushbookmarks']:
+ bookmark = reply['bookmark']
+ ret = int(reply['return'])
+ replies[bookmark] = ret
+ for book, action in booktoaction.items():
+ if book not in replies:
+ pushop.ui.warn(_('server ignored bookmark %s update\n') % book)
+ else:
+ ret = replies[book]
+ if ret:
+ ui.status(bookmsgmap[action][0] % book)
+ else:
+ ui.warn(bookmsgmap[action][1] % book)
+ if pushop.bkresult is not None:
+ pushop.bkresult = 1
+ return handlereply
+
@b2partsgenerator('bookmarks')
def _pushb2bookmarks(pushop, bundler):
"""handle bookmark push through bundle2"""
More information about the Mercurial-devel
mailing list