# HG changeset patch
# User mpm@selenic.com
# Date 1117651219 28800
#      Wed Jun 01 10:40:19 2005 -0800
# Node ID d2badbd7d1ad224a4f7554039dacdfb1a83be91e
# Parent  63af1db35611a22ebf5774feb05f6eb4505e7761
hg undo: fixup working dir state

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hg undo: fixup working dir state

manifest hash: 60fd7a5621f7c4e87c7c36097aaf11b22e7ee0b4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCngETywK+sNU5EO8RAiC/AKChvIgy61YfOLJcTQg5BKkTLLErRgCgnJMr
+xb+XsjeNfK+83MzeuE8UOk=
=EIlj
-----END PGP SIGNATURE-----

diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -417,9 +417,6 @@
 elif cmd == "recover":
     repo.recover()
 
-elif cmd == "undo":
-    repo.recover("undo")
-
 elif cmd == "verify":
     filelinkrevs = {}
     filenodes = {}
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -90,6 +90,9 @@
         for p,l in zip(zip(*pieces), lines):
             u.write(" ".join(p) + ": " + l[1])
 
+def undo(ui, repo, args):
+    repo.undo()
+
 table = {
     "init": (init, [], 'hg init'),
     "help": (help, [], 'hg init'),
@@ -100,6 +103,7 @@
                       ('n', 'number', None, 'show revision number'),
                       ('c', 'changeset', None, 'show changeset')],
                      'hg annotate [-u] [-c] [-n] [-r id] [files]'),
+    "undo": (undo, [], 'hg undo'),
     }
 
 norepo = "init branch help"
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -329,13 +329,35 @@
         return transaction(self.opener, self.join("journal"),
                            self.join("undo"))
 
-    def recover(self, f = "journal"):
+    def recover(self):
+        self.lock()
+        if os.path.exists(self.join("recover")):
+            self.ui.status("attempting to rollback interrupted transaction\n")
+            return rollback(self.opener, self.join("recover"))
+        else:
+            self.ui.warn("no interrupted transaction available\n")
+
+    def undo(self):
         self.lock()
-        if os.path.exists(self.join(f)):
-            self.ui.status("attempting to rollback %s information\n" % f)
-            return rollback(self.opener, self.join(f))
+        if os.path.exists(self.join("undo")):
+            self.ui.status("attempting to rollback last transaction\n")
+            rollback(self.opener, self.join("undo"))
+            self.manifest = manifest(self.opener)
+            self.changelog = changelog(self.opener)
+
+            self.ui.status("discarding dircache\n")
+            node = self.changelog.tip()
+            mf = self.changelog.read(node)[0]
+            mm = self.manifest.read(mf)
+            f = mm.keys()
+            f.sort()
+
+            self.setcurrent(node)
+            self.dircache.clear()
+            self.dircache.taint(f)
+        
         else:
-            self.ui.warn("no %s information available\n" % f)
+            self.ui.warn("no undo information available\n")
 
     def lock(self, wait = 1):
         try:
@@ -476,7 +498,7 @@
                 if fn in dc:
                     c = dc[fn]
                     del dc[fn]
-                    if not c:
+                    if not c or c[1] < 0:
                         if fcmp(fn):
                             changed.append(fn)
                     elif c[1] != s.st_size: