diff mercurial/changegroup.py @ 22960:7c13c9404c2c

changegroup: use a copy of hookargs when invoking the changegroup hook addchangegroup creates a runhook function that is used to invoke the changegroup and incoming hooks, but at the time the function is called, the contents of hookargs associated with the transaction may have been modified externally. For instance, bundle2 code affects it with obsolescence markers and bookmarks info. It also creates problems when a single transaction is used with multiple changegroups added (as per an upcoming change), whereby the contents of hookargs are that of after adding a latter changegroup when invoking the hook for the first changegroup.
author Mike Hommey <mh@glandium.org>
date Thu, 16 Oct 2014 15:54:53 +0900
parents e2806b8613ca
children 01e98eba3bc1
line wrap: on
line diff
--- a/mercurial/changegroup.py	Thu Oct 16 13:48:51 2014 +0900
+++ b/mercurial/changegroup.py	Thu Oct 16 15:54:53 2014 +0900
@@ -687,8 +687,12 @@
             p = lambda: cl.writepending() and repo.root or ""
             if 'node' not in tr.hookargs:
                 tr.hookargs['node'] = hex(cl.node(clstart))
+                hookargs = dict(tr.hookargs)
+            else:
+                hookargs = dict(tr.hookargs)
+                hookargs['node'] = hex(cl.node(clstart))
             repo.hook('pretxnchangegroup', throw=True, source=srctype,
-                      url=url, pending=p, **tr.hookargs)
+                      url=url, pending=p, **hookargs)
 
         added = [cl.node(r) for r in xrange(clstart, clend)]
         publishing = repo.ui.configbool('phases', 'publish', True)
@@ -724,6 +728,7 @@
                 # `destroyed` will repair it.
                 # In other case we can safely update cache on disk.
                 branchmap.updatecache(repo.filtered('served'))
+
             def runhooks():
                 # These hooks run when the lock releases, not when the
                 # transaction closes. So it's possible for the changelog
@@ -734,7 +739,7 @@
                 # forcefully update the on-disk branch cache
                 repo.ui.debug("updating the branch cache\n")
                 repo.hook("changegroup", source=srctype, url=url,
-                          **tr.hookargs)
+                          **hookargs)
 
                 for n in added:
                     repo.hook("incoming", node=hex(n), source=srctype,