diff mercurial/bundle2.py @ 35261:f392066d127c

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'.
author Boris Feld <boris.feld@octobus.net>
date Tue, 17 Oct 2017 12:07:24 +0200
parents af5507203d01
children 1f30cbac34b6
line wrap: on
line diff
--- a/mercurial/bundle2.py	Sun Oct 15 18:02:11 2017 +0200
+++ b/mercurial/bundle2.py	Tue Oct 17 12:07:24 2017 +0200
@@ -1989,7 +1989,31 @@
     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):