addremove: atomically update the dirstate
In case someone hits ^C during the similarity search, properly rollback
--- 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