changeset 17471:ad1561723dde

amend: lock the repository during the whole process Without this changes another writer can lock the repository in the middle the amend process. The resulting mess can be pretty ugly.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sat, 25 Aug 2012 15:37:28 +0200
parents 89467a7c2132
children 965fbe04fd96
files mercurial/cmdutil.py
diffstat 1 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Mon Sep 10 14:08:10 2012 -0700
+++ b/mercurial/cmdutil.py	Sat Aug 25 15:37:28 2012 +0200
@@ -11,6 +11,7 @@
 import util, scmutil, templater, patch, error, templatekw, revlog, copies
 import match as matchmod
 import subrepo, context, repair, bookmarks, graphmod, revset, phases
+import lock as lockmod
 
 def parsealiases(cmd):
     return cmd.lstrip("^").split("|")
@@ -1575,8 +1576,10 @@
     ui.note(_('amending changeset %s\n') % old)
     base = old.p1()
 
-    wlock = repo.wlock()
+    wlock = lock = None
     try:
+        wlock = repo.wlock()
+        lock = repo.lock()
         # First, do a regular commit to record all changes in the working
         # directory (if there are any)
         ui.callhooks = False
@@ -1694,16 +1697,12 @@
 
             # Strip the intermediate commit (if there was one) and the amended
             # commit
-            lock = repo.lock()
-            try:
-                if node:
-                    ui.note(_('stripping intermediate changeset %s\n') % ctx)
-                ui.note(_('stripping amended changeset %s\n') % old)
-                repair.strip(ui, repo, old.node(), topic='amend-backup')
-            finally:
-                lock.release()
+            if node:
+                ui.note(_('stripping intermediate changeset %s\n') % ctx)
+            ui.note(_('stripping amended changeset %s\n') % old)
+            repair.strip(ui, repo, old.node(), topic='amend-backup')
     finally:
-        wlock.release()
+        lockmod.release(wlock, lock)
     return newid
 
 def commiteditor(repo, ctx, subs):