hg undo: fixup working dir state
authormpm@selenic.com
Wed, 01 Jun 2005 10:40:19 -0800
changeset 210 d2badbd7d1ad224a4f7554039dacdfb1a83be91e
parent 209 63af1db35611a22ebf5774feb05f6eb4505e7761
child 211 426d3c3ae3630b31ba93a692aa175cc2f4018597
push id1
push usergszorc@mozilla.com
push dateWed, 18 Mar 2015 16:34:57 +0000
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-----
hg
mercurial/commands.py
mercurial/hg.py
--- a/hg
+++ b/hg
@@ -412,19 +412,16 @@ elif cmd == "tags":
             r = repo.changelog.rev(n)
         except KeyError:
             r = "?"
         print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n))
 
 elif cmd == "recover":
     repo.recover()
 
-elif cmd == "undo":
-    repo.recover("undo")
-
 elif cmd == "verify":
     filelinkrevs = {}
     filenodes = {}
     manifestchangeset = {}
     changesets = revisions = files = 0
     errors = 0
 
     ui.status("checking changesets\n")
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -85,26 +85,30 @@ def annotate(u, repo, args, **ops):
             if ops[o]:
                 l = [ f(n) for n,t in lines ]
                 m = max(map(len, l))
                 pieces.append([ "%*s" % (m, x) for x in l])
 
         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'),
     "checkout|co": (checkout, [], 'hg init'),
     "ann|annotate": (annotate,
                      [('r', 'revision', '', 'revision'),
                       ('u', 'user', None, 'show user'),
                       ('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"
 
 def dispatch(args):
     options = {}
     opts = [('v', 'verbose', None, 'verbose'),
             ('d', 'debug', None, 'debug'),
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -324,23 +324,45 @@ class localrepository:
     def file(self, f):
         if f[0] == '/': f = f[1:]
         return filelog(self.opener, f)
 
     def transaction(self):
         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:
             return lock.lock(self.join("lock"), 0)
         except lock.LockHeld, inst:
             if wait:
                 self.ui.warn("waiting for lock held by %s\n" % inst.args[0])
                 return lock.lock(self.join("lock"), wait)
@@ -471,17 +493,17 @@ class localrepository:
             
             for f in files:
                 fn = os.path.join(d, f)
                 try: s = os.stat(os.path.join(self.root, fn))
                 except: continue
                 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:
                         changed.append(fn)
                     elif c[0] != s.st_mode or c[2] != s.st_mtime:
                         if fcmp(fn):
                             changed.append(fn)
                 else: