changeset 6109:242595e612ed

revert: unify forget and remove lists This doesn't make a difference right now, but after the next revision some files in state 'a' may end up in the deleted list, and revert won't be able to just remove all files in that list.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Thu, 14 Feb 2008 18:08:16 -0200
parents 5086576a2152
children 81e20e01d465
files mercurial/commands.py tests/test-revert tests/test-revert.out
diffstat 3 files changed, 40 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Feb 14 18:08:16 2008 -0200
+++ b/mercurial/commands.py	Thu Feb 14 18:08:16 2008 -0200
@@ -2246,10 +2246,14 @@
                 removed[src] = None
                 names[src] = (repo.pathto(src, cwd), True)
 
+        def removeforget(abs):
+            if repo.dirstate[abs] == 'a':
+                return _('forgetting %s\n')
+            return _('removing %s\n')
+
         revert = ([], _('reverting %s\n'))
         add = ([], _('adding %s\n'))
-        remove = ([], _('removing %s\n'))
-        forget = ([], _('forgetting %s\n'))
+        remove = ([], removeforget)
         undelete = ([], _('undeleting %s\n'))
 
         disptable = (
@@ -2260,7 +2264,7 @@
             #   make backup if in target manifest
             #   make backup if not in target manifest
             (modified, revert, remove, True, True),
-            (added, revert, forget, True, False),
+            (added, revert, remove, True, False),
             (removed, undelete, None, False, False),
             (deleted, revert, remove, False, False),
             )
@@ -2280,7 +2284,10 @@
                     if not opts.get('dry_run'):
                         util.copyfile(target, bakname)
                 if ui.verbose or not exact:
-                    ui.status(xlist[1] % rel)
+                    msg = xlist[1]
+                    if not isinstance(msg, basestring):
+                        msg = msg(abs)
+                    ui.status(msg % rel)
             for table, hitlist, misslist, backuphit, backupmiss in disptable:
                 if abs not in table: continue
                 # file has changed in dirstate
@@ -2319,8 +2326,17 @@
                 fc = ctx[f]
                 repo.wwrite(f, fc.data(), fc.fileflags())
 
-            for f in forget[0]:
-                repo.dirstate.forget(f)
+            audit_path = util.path_auditor(repo.root)
+            for f in remove[0]:
+                if repo.dirstate[f] == 'a':
+                    repo.dirstate.forget(f)
+                    continue
+                audit_path(f)
+                try:
+                    util.unlink(repo.wjoin(f))
+                except OSError:
+                    pass
+                repo.dirstate.remove(f)
 
             for f in revert[0]:
                 checkout(f)
@@ -2336,14 +2352,6 @@
                 checkout(f)
                 normal(f)
 
-            audit_path = util.path_auditor(repo.root)
-            for f in remove[0]:
-                audit_path(f)
-                try:
-                    util.unlink(repo.wjoin(f))
-                except OSError:
-                    pass
-                repo.dirstate.remove(f)
     finally:
         del wlock
 
--- a/tests/test-revert	Thu Feb 14 18:08:16 2008 -0200
+++ b/tests/test-revert	Thu Feb 14 18:08:16 2008 -0200
@@ -28,7 +28,16 @@
 hg revert --no-backup c
 echo %% should show unknown: b
 hg status
-echo %% should show a b c e
+hg add b
+echo %% should show b added
+hg status b
+rm b
+echo %% should show b added
+hg status b
+hg revert -v b
+echo %% should not find b
+hg status b
+echo %% should show a c e
 ls
 echo %% should verbosely save backup to e.orig
 echo z > e
--- a/tests/test-revert.out	Thu Feb 14 18:08:16 2008 -0200
+++ b/tests/test-revert.out	Thu Feb 14 18:08:16 2008 -0200
@@ -18,9 +18,15 @@
 ? b
 %% should show unknown: b
 ? b
-%% should show a b c e
+%% should show b added
+A b
+%% should show b added
+A b
+forgetting b
+%% should not find b
+b: No such file or directory
+%% should show a c e
 a
-b
 c
 e
 %% should verbosely save backup to e.orig
@@ -33,7 +39,6 @@
 %% should say file not found
 notfound: No such file in rev 095eacd0c0d7
 A z
-? b
 ? e.orig
 %% should add a, remove d, forget z
 adding a