addremove: build lists of already added and removed files too (issue1696)
authorMatt Mackall <mpm@selenic.com>
Tue, 30 Jun 2009 23:25:53 -0500
changeset 8990 627399330c7d
parent 8989 85b81cac9613
child 8991 7e0b31dfc66f
addremove: build lists of already added and removed files too (issue1696)
mercurial/cmdutil.py
tests/test-addremove
tests/test-addremove.out
--- a/mercurial/cmdutil.py	Tue Jun 30 16:11:42 2009 -0500
+++ b/mercurial/cmdutil.py	Tue Jun 30 23:25:53 2009 -0500
@@ -298,7 +298,8 @@
         dry_run = opts.get('dry_run')
     if similarity is None:
         similarity = float(opts.get('similarity') or 0)
-    unknown, deleted = [], []
+    # we'd use status here, except handling of symlinks and ignore is tricky
+    added, unknown, deleted, removed = [], [], [], []
     audit_path = util.path_auditor(repo.root)
     m = match(repo, pats, opts)
     for abs in repo.walk(m):
@@ -314,16 +315,22 @@
             unknown.append(abs)
             if repo.ui.verbose or not exact:
                 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
-        if repo.dirstate[abs] != 'r' and (not good or not util.lexists(target)
+        elif repo.dirstate[abs] != 'r' and (not good or not util.lexists(target)
             or (os.path.isdir(target) and not os.path.islink(target))):
             deleted.append(abs)
             if repo.ui.verbose or not exact:
                 repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
+        # for finding renames
+        elif repo.dirstate[abs] == 'r':
+            removed.append(abs)
+        elif repo.dirstate[abs] == 'a':
+            added.append(abs)
     if not dry_run:
         repo.remove(deleted)
         repo.add(unknown)
     if similarity > 0:
-        for old, new, score in findrenames(repo, unknown, deleted, similarity):
+        for old, new, score in findrenames(repo, added + unknown,
+                                           removed + deleted, similarity):
             if repo.ui.verbose or not m.exact(old) or not m.exact(new):
                 repo.ui.status(_('recording removal of %s as rename to %s '
                                  '(%d%% similar)\n') %
--- a/tests/test-addremove	Tue Jun 30 16:11:42 2009 -0500
+++ b/tests/test-addremove	Tue Jun 30 23:25:53 2009 -0500
@@ -22,5 +22,6 @@
 mv a b
 rm c
 echo d > d
+hg addremove -n -s 50 # issue 1696
 hg addremove -s 50
 hg commit -mb
--- a/tests/test-addremove.out	Tue Jun 30 16:11:42 2009 -0500
+++ b/tests/test-addremove.out	Tue Jun 30 23:25:53 2009 -0500
@@ -15,3 +15,8 @@
 removing c
 adding d
 recording removal of a as rename to b (100% similar)
+removing a
+adding b
+removing c
+adding d
+recording removal of a as rename to b (100% similar)