[PATCH 4 of 8 V5] bundle2: add check:bookmarks part handler

Stanislau Hlebik stash at fb.com
Fri Sep 16 07:10:32 EDT 2016


# HG changeset patch
# User Stanislau Hlebik <stash at fb.com>
# Date 1473955024 25200
#      Thu Sep 15 08:57:04 2016 -0700
# Node ID 7dd18199a5c4e890b634312684a1a05db2fbaac9
# Parent  3456cba8a4879e74f3b928df321ce7e7c695fb4c
bundle2: add check:bookmarks part handler

New `bookmark` part doesn't use pushkey infrastructure and doesn't prevent
bookmarks race conditions. So we need new a part handler similar to check:heads
that will check bookmark race conditions during push.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -156,6 +156,7 @@
 from .i18n import _
 from .node import (
     bin,
+    hex,
 )
 from . import (
     changegroup,
@@ -1469,6 +1470,21 @@
         raise error.PushRaced('repository changed while pushing - '
                               'please try again')
 
+ at parthandler('check:bookmarks')
+def handlecheckbookmarks(op, inpart):
+    """check that bookmarks did not change
+
+    This is used to detect a push race when using unbundle.
+    """
+    dec = encoding.tolocal
+    for bookmarkoldnode in inpart.read().splitlines():
+        bookmark, oldnode = bookmarkoldnode.rsplit(' ', 1)
+        bookmark = dec(bookmark)
+        marks = op.repo._bookmarks
+        if bookmark not in marks or hex(marks[bookmark]) != oldnode:
+            raise error.PushRaced('repository changed while pushing - '
+                                  'please try again')
+
 @parthandler('output')
 def handleoutput(op, inpart):
     """forward output captured on the server to the client"""


More information about the Mercurial-devel mailing list