continue: ensure we hold the wlock before writing file to disk
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 11 Aug 2016 23:00:46 +0200
changeset 1722 b4be34677fda
parent 1721 d3429d25e0cb
child 1723 2672f36d668e
continue: ensure we hold the wlock before writing file to disk A hack in 'hg evolve --continue' involve writing a 'graftstate' file. We take the wlock before doing so.
hgext/evolve.py
--- a/hgext/evolve.py	Tue Aug 09 00:37:58 2016 +0200
+++ b/hgext/evolve.py	Thu Aug 11 23:00:46 2016 +0200
@@ -1794,14 +1794,18 @@
             raise error.Abort('no evolve to continue')
         orig = repo[state['current']]
         # XXX This is a terrible terrible hack, please get rid of it.
-        repo.opener.write('graftstate', orig.hex() + '\n')
+        lock = repo.wlock()
         try:
-            graftcmd = commands.table['graft'][0]
-            ret = graftcmd(ui, repo, old_obsolete=True, **{'continue': True})
-            _evolvestatedelete(repo)
-            return ret
+            repo.opener.write('graftstate', orig.hex() + '\n')
+            try:
+                graftcmd = commands.table['graft'][0]
+                ret = graftcmd(ui, repo, old_obsolete=True, **{'continue': True})
+                _evolvestatedelete(repo)
+                return ret
+            finally:
+                util.unlinkpath(repo.join('graftstate'), ignoremissing=True)
         finally:
-            util.unlinkpath(repo.join('graftstate'), ignoremissing=True)
+            lock.release()
     cmdutil.bailifchanged(repo)