Patchwork [05,of,12,V3] bookmark: add pushkey hook compatiblity to the bundle2 part

login
register
mail settings
Submitter Boris Feld
Date Nov. 20, 2017, 4:51 p.m.
Message ID <fd2b6b05ecbe8aeb0d84.1511196716@FB>
Download mbox | patch
Permalink /patch/25657/
State Accepted
Headers show

Comments

Boris Feld - Nov. 20, 2017, 4:51 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1508234844 -7200
#      Tue Oct 17 12:07:24 2017 +0200
# Node ID fd2b6b05ecbe8aeb0d844112be6cc5d0e72a62bd
# Parent  17f26502af06258ceadceffc6e2ff445b4b18e7d
# EXP-Topic b2.bookmarks
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r fd2b6b05ecbe
bookmark: add pushkey hook compatiblity to the bundle2 part

Currently, pushing a bookmark update triggers a pushkey hooks. It is likely
that users in the wild use such hooks to control bookmark movement. Using a non
push-key mechanism to exchange bookmark means these hooks are no longer called,
possibly breaking existing users setup. So we add explicit call to the pushkey
hooks in the handling of the bundle2 part. This behavior can be disabled with a
new config knob: 'server.bookmarks-pushkey-compat'.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1905,7 +1905,31 @@  def handlebookmark(op, inpart):
     for pull.
     """
     changes = bookmarks.binarydecode(inpart)
-    op.repo._bookmarks.applychanges(op.repo, op.gettransaction(), changes)
+
+    tr = op.gettransaction()
+    bookstore = op.repo._bookmarks
+
+    pushkeycompat = op.repo.ui.configbool('server', 'bookmarks-pushkey-compat')
+    if pushkeycompat:
+        allhooks = []
+        for book, node in changes:
+            hookargs = tr.hookargs.copy()
+            hookargs['pushkeycompat'] = '1'
+            hookargs['namespace'] = 'bookmark'
+            hookargs['key'] = book
+            hookargs['old'] = nodemod.hex(bookstore.get(book, ''))
+            hookargs['new'] = nodemod.hex(node if node is not None else '')
+            allhooks.append(hookargs)
+        for hookargs in allhooks:
+            op.repo.hook('prepushkey', throw=True, **hookargs)
+
+    bookstore.applychanges(op.repo, tr, changes)
+
+    if pushkeycompat:
+        def runhook():
+            for hookargs in allhooks:
+                op.repo.hook('prepushkey', **hookargs)
+        op.repo._afterlock(runhook)
 
 @parthandler('phase-heads')
 def handlephases(op, inpart):
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -742,6 +742,9 @@  coreconfigitem('progress', 'width',
 coreconfigitem('push', 'pushvars.server',
     default=False,
 )
+coreconfigitem('server', 'bookmarks-pushkey-compat',
+    default=True,
+)
 coreconfigitem('server', 'bundle1',
     default=True,
 )
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1723,6 +1723,14 @@  Alias definitions for revsets. See :hg:`
 
 Controls generic server settings.
 
+``bookmarks-pushkey-compat``
+    Trigger pushkey hook when being pushed bookmark updates. This config exist
+    for compatibility purpose (default to True)
+
+    If you use ``pushkey`` and ``pre-pushkey`` hooks to control bookmark
+    movement we recommend you migrate them to ``txnclose-bookmark`` and
+    ``pretxnclose-bookmark``.
+
 ``compressionengines``
     List of compression engines and their relative priority to advertise
     to clients.