changeset 1722:b4be34677fda

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.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Thu, 11 Aug 2016 23:00:46 +0200
parents d3429d25e0cb
children 2672f36d668e
files hgext/evolve.py
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)