# HG changeset patch
# User Stanislau Hlebik <st...@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')
 
+@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"""
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to