changeset 10606:5868dd69fb03

addremove: atomically update the dirstate In case someone hits ^C during the similarity search, properly rollback
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 07 Mar 2010 23:59:28 +0100
parents 3077ee5ca750
children f3ac9d6105ee
files mercurial/cmdutil.py
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sun Mar 07 13:10:23 2010 -0500
+++ b/mercurial/cmdutil.py	Sun Mar 07 23:59:28 2010 +0100
@@ -356,9 +356,7 @@
             removed.append(abs)
         elif repo.dirstate[abs] == 'a':
             added.append(abs)
-    if not dry_run:
-        repo.remove(deleted)
-        repo.add(unknown)
+    copies = {}
     if similarity > 0:
         for old, new, score in findrenames(repo, added + unknown,
                                            removed + deleted, similarity):
@@ -366,8 +364,17 @@
                 repo.ui.status(_('recording removal of %s as rename to %s '
                                  '(%d%% similar)\n') %
                                (m.rel(old), m.rel(new), score * 100))
-            if not dry_run:
+            copies[new] = old
+
+    if not dry_run:
+        wlock = repo.wlock()
+        try:
+            repo.remove(deleted)
+            repo.add(unknown)
+            for new, old in copies.iteritems():
                 repo.copy(old, new)
+        finally:
+            wlock.release()
 
 def copy(ui, repo, pats, opts, rename=False):
     # called with the repo lock held