rollback: only restore dirstate and branch when appropriate.
authorGreg Ward <greg@gerg.ca>
Sun, 18 Sep 2011 19:59:33 -0400
changeset 15131 7c26ce9edbd2
parent 15130 3d44e68360a6
child 15132 81f76098211e
rollback: only restore dirstate and branch when appropriate. If the working dir parent was destroyed by rollback, then the old behaviour is perfectly reasonable: restore dirstate, branch, and bookmarks. That way the working dir moves back to an existing changeset rather than becoming an orphan. But if the working dir parent was unaffected -- say, you updated to an older changeset and then did rollback -- then it's silly to restore dirstate and branch. So don't do that. Leave the status of the working dir alone. (But always restore bookmarks, because that file refers to changeset IDs that may have been destroyed.)
mercurial/localrepo.py
tests/test-acl.t
tests/test-bundle-r.t
tests/test-bundle.t
tests/test-convert-cvs.t
tests/test-eol-hook.t
tests/test-hook.t
tests/test-import-bypass.t
tests/test-notify-changegroup.t
tests/test-notify.t
tests/test-push-http.t
tests/test-rollback.t
tests/test-url-rev.t
--- a/mercurial/localrepo.py	Fri Sep 16 21:38:06 2011 -0400
+++ b/mercurial/localrepo.py	Sun Sep 18 19:59:33 2011 -0400
@@ -789,28 +789,35 @@
         ui.status(msg)
         if dryrun:
             return 0
+
+        parents = self.dirstate.parents()
         transaction.rollback(self.sopener, self.sjoin('undo'), ui.warn)
-        util.rename(self.join('undo.dirstate'), self.join('dirstate'))
         if os.path.exists(self.join('undo.bookmarks')):
             util.rename(self.join('undo.bookmarks'),
                         self.join('bookmarks'))
-        try:
-            branch = self.opener.read('undo.branch')
-            self.dirstate.setbranch(branch)
-        except IOError:
-            ui.warn(_('named branch could not be reset: '
-                      'current branch is still \'%s\'\n')
-                    % self.dirstate.branch())
         self.invalidate()
-        self.dirstate.invalidate()
-        self.destroyed()
-        parents = tuple([p.rev() for p in self.parents()])
-        if len(parents) > 1:
-            ui.status(_('working directory now based on '
-                        'revisions %d and %d\n') % parents)
-        else:
-            ui.status(_('working directory now based on '
-                        'revision %d\n') % parents)
+
+        parentgone = (parents[0] not in self.changelog.nodemap or
+                      parents[1] not in self.changelog.nodemap)
+        if parentgone:
+            util.rename(self.join('undo.dirstate'), self.join('dirstate'))
+            try:
+                branch = self.opener.read('undo.branch')
+                self.dirstate.setbranch(branch)
+            except IOError:
+                ui.warn(_('named branch could not be reset: '
+                          'current branch is still \'%s\'\n')
+                        % self.dirstate.branch())
+
+            self.dirstate.invalidate()
+            self.destroyed()
+            parents = tuple([p.rev() for p in self.parents()])
+            if len(parents) > 1:
+                ui.status(_('working directory now based on '
+                            'revisions %d and %d\n') % parents)
+            else:
+                ui.status(_('working directory now based on '
+                            'revision %d\n') % parents)
         return 0
 
     def invalidatecaches(self):
--- a/tests/test-acl.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-acl.t	Sun Sep 18 19:59:33 2011 -0400
@@ -121,7 +121,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 0 (undo push)
-  working directory now based on revision 0
   0:6675d58eff77
   
 
@@ -179,7 +178,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 0 (undo push)
-  working directory now based on revision 0
   0:6675d58eff77
   
 
@@ -247,7 +245,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 0 (undo push)
-  working directory now based on revision 0
   0:6675d58eff77
   
 
@@ -729,7 +726,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 0 (undo push)
-  working directory now based on revision 0
   0:6675d58eff77
   
 
@@ -1038,7 +1034,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 0 (undo push)
-  working directory now based on revision 0
   0:6675d58eff77
   
 
@@ -1114,7 +1109,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 0 (undo push)
-  working directory now based on revision 0
   0:6675d58eff77
   
 
@@ -1261,7 +1255,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 0 (undo push)
-  working directory now based on revision 0
   0:6675d58eff77
   
 
@@ -1456,7 +1449,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 2 (undo push)
-  working directory now based on revision 2
   2:fb35475503ef
   
 
@@ -1753,7 +1745,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 2 (undo push)
-  working directory now based on revision 2
   2:fb35475503ef
   
 
@@ -1838,7 +1829,6 @@
   updating the branch cache
   checking for updated bookmarks
   repository tip rolled back to revision 2 (undo push)
-  working directory now based on revision 2
   2:fb35475503ef
   
 Branch acl conflicting deny
--- a/tests/test-bundle-r.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-bundle-r.t	Sun Sep 18 19:59:33 2011 -0400
@@ -154,7 +154,6 @@
   4 files, 9 changesets, 7 total revisions
   $ hg rollback
   repository tip rolled back to revision 4 (undo pull)
-  working directory now based on revision -1
   $ cd ..
 
 should fail
@@ -232,7 +231,6 @@
   4 files, 9 changesets, 7 total revisions
   $ hg rollback
   repository tip rolled back to revision 2 (undo unbundle)
-  working directory now based on revision 2
 
 revision 2
 
@@ -257,7 +255,6 @@
   2 files, 5 changesets, 5 total revisions
   $ hg rollback
   repository tip rolled back to revision 2 (undo unbundle)
-  working directory now based on revision 2
   $ hg unbundle ../test-bundle-branch2.hg
   adding changesets
   adding manifests
@@ -277,7 +274,6 @@
   3 files, 7 changesets, 6 total revisions
   $ hg rollback
   repository tip rolled back to revision 2 (undo unbundle)
-  working directory now based on revision 2
   $ hg unbundle ../test-bundle-cset-7.hg
   adding changesets
   adding manifests
--- a/tests/test-bundle.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-bundle.t	Sun Sep 18 19:59:33 2011 -0400
@@ -90,7 +90,6 @@
 
   $ hg -R empty rollback
   repository tip rolled back to revision -1 (undo pull)
-  working directory now based on revision -1
 
 Pull full.hg into empty again (using --cwd)
 
@@ -121,7 +120,6 @@
 
   $ hg -R empty rollback
   repository tip rolled back to revision -1 (undo pull)
-  working directory now based on revision -1
 
 Pull full.hg into empty again (using -R)
 
@@ -219,7 +217,6 @@
 
   $ hg rollback
   repository tip rolled back to revision -1 (undo pull)
-  working directory now based on revision -1
   $ cd ..
 
 Log -R bundle:empty+full.hg
--- a/tests/test-convert-cvs.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-convert-cvs.t	Sun Sep 18 19:59:33 2011 -0400
@@ -112,7 +112,6 @@
   1 import
   filtering out empty revision
   repository tip rolled back to revision 0 (undo commit)
-  working directory now based on revision -1
   0 ci0
   updating tags
   $ hgcat b/c
--- a/tests/test-eol-hook.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-eol-hook.t	Sun Sep 18 19:59:33 2011 -0400
@@ -161,7 +161,6 @@
   added 3 changesets with 3 changes to 2 files (+1 heads)
   $ hg -R ../main rollback
   repository tip rolled back to revision 5 (undo push)
-  working directory now based on revision -1
 
 Test it still fails with checkallhook
 
--- a/tests/test-hook.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-hook.t	Sun Sep 18 19:59:33 2011 -0400
@@ -277,7 +277,6 @@
   (run 'hg update' to get a working copy)
   $ hg rollback
   repository tip rolled back to revision 3 (undo pull)
-  working directory now based on revision 0
 
 preoutgoing hook can prevent outgoing changes
 
--- a/tests/test-import-bypass.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-import-bypass.t	Sun Sep 18 19:59:33 2011 -0400
@@ -62,7 +62,6 @@
   
   $ hg rollback
   repository tip rolled back to revision 1 (undo commit)
-  working directory now based on revision 0
 
 Test --import-branch
 
@@ -75,7 +74,6 @@
   
   $ hg rollback
   repository tip rolled back to revision 1 (undo commit)
-  working directory now based on revision 0
 
 Test --strip
 
@@ -98,7 +96,6 @@
   applying patch from stdin
   $ hg rollback
   repository tip rolled back to revision 1 (undo commit)
-  working directory now based on revision 0
 
 Test unsupported combinations
 
--- a/tests/test-notify-changegroup.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-notify-changegroup.t	Sun Sep 18 19:59:33 2011 -0400
@@ -74,7 +74,6 @@
   +a
   $ hg --cwd a rollback
   repository tip rolled back to revision -1 (undo push)
-  working directory now based on revision -1
 
 unbundle with unrelated source
 
@@ -89,7 +88,6 @@
   (run 'hg update' to get a working copy)
   $ hg --cwd a rollback
   repository tip rolled back to revision -1 (undo unbundle)
-  working directory now based on revision -1
 
 unbundle with correct source
 
--- a/tests/test-notify.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-notify.t	Sun Sep 18 19:59:33 2011 -0400
@@ -200,7 +200,6 @@
 
   $ hg --cwd b rollback
   repository tip rolled back to revision 0 (undo pull)
-  working directory now based on revision 0
   $ hg --cwd b pull ../a 2>&1 | grep 'error.*\.notify\.conf' > /dev/null && echo pull failed
   pull failed
   $ touch ".notify.conf"
@@ -209,7 +208,6 @@
 
   $ hg --cwd b rollback
   repository tip rolled back to revision 0 (undo pull)
-  working directory now based on revision 0
   $ hg --traceback --cwd b pull ../a  | \
   >   python -c 'import sys,re; print re.sub("\n\t", " ", sys.stdin.read()),'
   pulling from ../a
@@ -254,7 +252,6 @@
 
   $ hg --cwd b rollback
   repository tip rolled back to revision 0 (undo pull)
-  working directory now based on revision 0
   $ hg --traceback --cwd b pull ../a | \
   >   python -c 'import sys,re; print re.sub("\n\t", " ", sys.stdin.read()),'
   pulling from ../a
--- a/tests/test-push-http.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-push-http.t	Sun Sep 18 19:59:33 2011 -0400
@@ -64,7 +64,6 @@
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
-  working directory now based on revision 0
 
 expect success, server lacks the httpheader capability
 
@@ -81,7 +80,6 @@
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
-  working directory now based on revision 0
 
 expect success, server lacks the unbundlehash capability
 
@@ -98,7 +96,6 @@
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
-  working directory now based on revision 0
 
 expect authorization error: all users denied
 
--- a/tests/test-rollback.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-rollback.t	Sun Sep 18 19:59:33 2011 -0400
@@ -64,6 +64,35 @@
   $ hg branch
   test
 
+working dir unaffected by rollback: do not restore dirstate et. al.
+  $ hg log --template '{rev}  {branch}  {desc|firstline}\n'
+  0  default  add a again
+  $ hg status
+  M a
+  $ hg bookmark foo
+  $ hg commit -m'modify a again'
+  $ echo b > b
+  $ hg commit -Am'add b'
+  adding b
+  $ hg log --template '{rev}  {branch}  {desc|firstline}\n'
+  2  test  add b
+  1  test  modify a again
+  0  default  add a again
+  $ hg update default
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg bookmark bar
+  $ cat .hg/undo.branch ; echo
+  test
+  $ hg rollback
+  repository tip rolled back to revision 1 (undo commit)
+  $ hg id -n
+  0
+  $ hg branch
+  default
+  $ cat .hg/bookmarks.current ; echo
+  bar
+  $ hg bookmark --delete foo
+
 rollback by pretxncommit saves commit message (issue 1635)
 
   $ echo a >> a
@@ -102,18 +131,18 @@
   adding changesets
   adding manifests
   adding file changes
-  added 2 changesets with 2 changes to 1 files
+  added 3 changesets with 2 changes to 1 files (+1 heads)
   updating to branch default
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd u
   $ hg id default
-  8902593132ae
+  068774709090
 
 now rollback and observe that 'hg serve' reloads the repository and
 presents the correct tip changeset:
 
   $ hg -R ../t rollback
-  repository tip rolled back to revision 0 (undo commit)
+  repository tip rolled back to revision 1 (undo commit)
   working directory now based on revision 0
   $ hg id default
-  23b0221f3370
+  791dd2169706
--- a/tests/test-url-rev.t	Fri Sep 16 21:38:06 2011 -0400
+++ b/tests/test-url-rev.t	Sun Sep 18 19:59:33 2011 -0400
@@ -102,7 +102,6 @@
   $ cd clone
   $ hg rollback
   repository tip rolled back to revision 1 (undo push)
-  working directory now based on revision 1
 
   $ hg -q incoming
   2:faba9097cad4
@@ -147,10 +146,6 @@
 
   $ hg rollback
   repository tip rolled back to revision 1 (undo pull)
-  working directory now based on revision 1
-
-  $ hg up -C 0
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ hg parents -q
   0:1f0dee641bb7