unbundle: acquire 'wlock' when processing bundle2 (BC) (issue4596)
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 15 Apr 2015 01:16:40 -0400
changeset 24752 5640efd1b160
parent 24751 dc4daf028f9c
child 24754 5dc5cd7abbf5
unbundle: acquire 'wlock' when processing bundle2 (BC) (issue4596) A bundle2 may contain bookmark updates (or other extension content) that requires the 'wlock' to be written. As 'wlock' must be acquired before 'lock', we must stay on the side of caution and use both in all case to ensure their ordering.
mercurial/exchange.py
tests/test-bundle2-exchange.t
--- a/mercurial/exchange.py	Sun Apr 12 09:46:03 2015 -0400
+++ b/mercurial/exchange.py	Wed Apr 15 01:16:40 2015 -0400
@@ -10,6 +10,7 @@
 import errno, urllib
 import util, scmutil, changegroup, base85, error
 import discovery, phases, obsolete, bookmarks as bookmod, bundle2, pushkey
+import lock as lockmod
 
 def readbundle(ui, fh, fname, vfs=None):
     header = changegroup.readexactly(fh, 4)
@@ -1275,13 +1276,14 @@
     If the push was raced as PushRaced exception is raised."""
     r = 0
     # need a transaction when processing a bundle2 stream
-    tr = None
-    lock = repo.lock()
+    wlock = lock = tr = None
     try:
         check_heads(repo, heads, 'uploading changes')
         # push can proceed
         if util.safehasattr(cg, 'params'):
             try:
+                wlock = repo.wlock()
+                lock = repo.lock()
                 tr = repo.transaction(source)
                 tr.hookargs['source'] = source
                 tr.hookargs['url'] = url
@@ -1292,9 +1294,8 @@
                 exc.duringunbundle2 = True
                 raise
         else:
+            lock = repo.lock()
             r = changegroup.addchangegroup(repo, cg, source, url)
     finally:
-        if tr is not None:
-            tr.release()
-        lock.release()
+        lockmod.release(tr, lock, wlock)
     return r
--- a/tests/test-bundle2-exchange.t	Sun Apr 12 09:46:03 2015 -0400
+++ b/tests/test-bundle2-exchange.t	Wed Apr 15 01:16:40 2015 -0400
@@ -226,7 +226,6 @@
   remote: adding file changes
   remote: added 1 changesets with 0 changes to 0 files (-1 heads)
   remote: 1 new obsolescence markers
-  remote: "wlock" acquired after "lock" at: */mercurial/bookmarks.py:259 (pushbookmark) (glob)
   updating bookmark book_eea1
   pre-close-tip:02de42196ebe draft book_02de
   postclose-tip:02de42196ebe draft book_02de
@@ -305,7 +304,6 @@
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
-  remote: "wlock" acquired after "lock" at: */mercurial/bookmarks.py:259 (pushbookmark) (glob)
   updating bookmark book_5fdd
   remote: pre-close-tip:5fddd98957c8 draft book_5fdd
   remote: pushkey: lock state after "bookmarks"
@@ -357,7 +355,6 @@
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
-  remote: "wlock" acquired after "lock" at: */mercurial/bookmarks.py:259 (pushbookmark) (glob)
   updating bookmark book_32af
   pre-close-tip:02de42196ebe draft book_02de
   postclose-tip:02de42196ebe draft book_02de