##// END OF EJS Templates
localrepo: restore dirstate to one before rollbacking if not parent-gone...
FUJIWARA Katsunori -
r26631:e077ce38 default
parent child Browse files
Show More
@@ -11,7 +11,7 b' import peer, changegroup, subrepo, pushk'
11 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
11 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
12 import lock as lockmod
12 import lock as lockmod
13 import transaction, store, encoding, exchange, bundle2
13 import transaction, store, encoding, exchange, bundle2
14 import scmutil, util, extensions, hook, error, revset
14 import scmutil, util, extensions, hook, error, revset, cmdutil
15 import match as matchmod
15 import match as matchmod
16 import merge as mergemod
16 import merge as mergemod
17 import tags as tagsmod
17 import tags as tagsmod
@@ -1084,20 +1084,22 b' class localrepository(object):'
1084 lock.release()
1084 lock.release()
1085
1085
1086 def rollback(self, dryrun=False, force=False):
1086 def rollback(self, dryrun=False, force=False):
1087 wlock = lock = None
1087 wlock = lock = dsguard = None
1088 try:
1088 try:
1089 wlock = self.wlock()
1089 wlock = self.wlock()
1090 lock = self.lock()
1090 lock = self.lock()
1091 if self.svfs.exists("undo"):
1091 if self.svfs.exists("undo"):
1092 return self._rollback(dryrun, force)
1092 dsguard = cmdutil.dirstateguard(self, 'rollback')
1093
1094 return self._rollback(dryrun, force, dsguard)
1093 else:
1095 else:
1094 self.ui.warn(_("no rollback information available\n"))
1096 self.ui.warn(_("no rollback information available\n"))
1095 return 1
1097 return 1
1096 finally:
1098 finally:
1097 release(lock, wlock)
1099 release(dsguard, lock, wlock)
1098
1100
1099 @unfilteredmethod # Until we get smarter cache management
1101 @unfilteredmethod # Until we get smarter cache management
1100 def _rollback(self, dryrun, force):
1102 def _rollback(self, dryrun, force, dsguard):
1101 ui = self.ui
1103 ui = self.ui
1102 try:
1104 try:
1103 args = self.vfs.read('undo.desc').splitlines()
1105 args = self.vfs.read('undo.desc').splitlines()
@@ -1140,6 +1142,9 b' class localrepository(object):'
1140 parentgone = (parents[0] not in self.changelog.nodemap or
1142 parentgone = (parents[0] not in self.changelog.nodemap or
1141 parents[1] not in self.changelog.nodemap)
1143 parents[1] not in self.changelog.nodemap)
1142 if parentgone:
1144 if parentgone:
1145 # prevent dirstateguard from overwriting already restored one
1146 dsguard.close()
1147
1143 self.vfs.rename('undo.dirstate', 'dirstate')
1148 self.vfs.rename('undo.dirstate', 'dirstate')
1144 try:
1149 try:
1145 branch = self.vfs.read('undo.branch')
1150 branch = self.vfs.read('undo.branch')
@@ -428,6 +428,25 b' patches: import patch1 patch2; rollback'
428 working directory now based on revision 0
428 working directory now based on revision 0
429 $ hg --cwd b parents --template 'parent: {rev}\n'
429 $ hg --cwd b parents --template 'parent: {rev}\n'
430 parent: 0
430 parent: 0
431
432 Test that "hg rollback" doesn't restore dirstate to one at the
433 beginning of the rollbacked transaction in not-"parent-gone" case.
434
435 invoking pretxncommit hook will cause marking '.hg/dirstate' as a file
436 to be restored at rollbacking, after DirstateTransactionPlan (see wiki
437 page for detail).
438
439 $ hg --cwd b branch -q foobar
440 $ hg --cwd b commit -m foobar
441 $ hg --cwd b update 0 -q
442 $ hg --cwd b import ../patch1 ../patch2 --config hooks.pretxncommit=true
443 applying ../patch1
444 applying ../patch2
445 $ hg --cwd b update -q 1
446 $ hg --cwd b rollback -q
447 $ hg --cwd b parents --template 'parent: {rev}\n'
448 parent: 1
449
431 $ rm -r b
450 $ rm -r b
432
451
433
452
General Comments 0
You need to be logged in to leave comments. Login now