revert: better fix for not printing 'reverting' message
authorVadim Gelfer <vadim.gelfer@gmail.com>
Wed, 07 Jun 2006 13:16:25 -0700
changeset 2407 8fe3d60b7f19
parent 2406 4a678e408ce5
child 2408 6ed46bad9530
revert: better fix for not printing 'reverting' message
mercurial/commands.py
tests/test-backout.out
tests/test-revert.out
--- a/mercurial/commands.py	Wed Jun 07 10:33:26 2006 -0700
+++ b/mercurial/commands.py	Wed Jun 07 13:16:25 2006 -0700
@@ -2326,8 +2326,11 @@
                            'you must specify the revision to revert to'))
     else:
         node = parent
-    pmf = None
     mf = repo.manifest.read(repo.changelog.read(node)[0])
+    if node == parent:
+        pmf = mf
+    else:
+        pmf = None
 
     wlock = repo.wlock()
 
@@ -2353,7 +2356,7 @@
         names[abs] = (rel, exact)
         target_only[abs] = True
 
-    changes = repo.changes(node, match=names.has_key, wlock=wlock)
+    changes = repo.changes(match=names.has_key, wlock=wlock)
     modified, added, removed, deleted, unknown = map(dict.fromkeys, changes)
 
     revert = ([], _('reverting %s\n'))
@@ -2382,9 +2385,10 @@
     entries.sort()
 
     for abs, (rel, exact) in entries:
-        in_mf = abs in mf
+        mfentry = mf.get(abs)
         def handle(xlist, dobackup):
             xlist[0].append(abs)
+            update[abs] = 1
             if dobackup and not opts['no_backup'] and os.path.exists(rel):
                 bakname = "%s.orig" % rel
                 ui.note(_('saving current version of %s as %s\n') %
@@ -2396,7 +2400,7 @@
         for table, hitlist, misslist, backuphit, backupmiss in disptable:
             if abs not in table: continue
             # file has changed in dirstate
-            if in_mf:
+            if mfentry:
                 handle(hitlist, backuphit)
             elif misslist is not None:
                 handle(misslist, backupmiss)
@@ -2408,14 +2412,18 @@
             if node == parent:
                 if exact: ui.warn(_('no changes needed to %s\n' % rel))
                 continue
-            if not in_mf:
-                if pmf is None:
-                    # only need parent manifest in this unlikely case,
-                    # so do not read by default
-                    pmf = repo.manifest.read(repo.changelog.read(parent)[0])
-                if abs in pmf:
+            if pmf is None:
+                # only need parent manifest in this unlikely case,
+                # so do not read by default
+                pmf = repo.manifest.read(repo.changelog.read(parent)[0])
+            if abs in pmf:
+                if mfentry:
+                    # if version of file is same in parent and target
+                    # manifests, do nothing
+                    if pmf[abs] != mfentry:
+                        handle(revert, False)
+                else:
                     handle(remove, False)
-        update[abs] = True
 
     repo.dirstate.forget(forget[0])
     r = repo.update(node, False, True, update.has_key, False, wlock=wlock,
--- a/tests/test-backout.out	Wed Jun 07 10:33:26 2006 -0700
+++ b/tests/test-backout.out	Wed Jun 07 13:16:25 2006 -0700
@@ -1,5 +1,6 @@
 # basic operation
 adding a
+reverting a
 changeset 2:b38a34ddfd9f backs out changeset 1:a820f4f40a57
 a
 # file that was removed is recreated
@@ -13,6 +14,7 @@
 cat: a: No such file or directory
 # backout with merge
 adding a
+reverting a
 changeset 3:6c77ecc28460 backs out changeset 1:314f55b1bf23
 merging with changeset 2:b66ea5b77abb
 merging a
--- a/tests/test-revert.out	Wed Jun 07 10:33:26 2006 -0700
+++ b/tests/test-revert.out	Wed Jun 07 13:16:25 2006 -0700
@@ -54,3 +54,4 @@
 %% issue 241
 adding a
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+reverting a