Rev 5635: (broken) Intermediate state to make reset_tree work even when things are broken. in http://bazaar.launchpad.net/~jameinel/bzr/2.4-reset-checkout
John Arbash Meinel
john at arbash-meinel.com
Mon Jan 24 23:59:10 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.4-reset-checkout
------------------------------------------------------------
revno: 5635
revision-id: john at arbash-meinel.com-20110124235857-ire0uaqf4t9oq8qj
parent: john at arbash-meinel.com-20110124225704-h2zdtk0a82q6bgwy
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.4-reset-checkout
timestamp: Mon 2011-01-24 17:58:57 -0600
message:
(broken) Intermediate state to make reset_tree work even when things are broken.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_workingtree/test_check_state.py'
--- a/bzrlib/tests/per_workingtree/test_check_state.py 2011-01-24 22:57:04 +0000
+++ b/bzrlib/tests/per_workingtree/test_check_state.py 2011-01-24 23:58:57 +0000
@@ -23,18 +23,19 @@
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
+
class TestCaseWithState(TestCaseWithWorkingTree):
def make_tree_with_broken_dirstate(self, path):
tree = self.make_branch_and_tree(path)
+ self.break_dirstate(tree)
+ return tree
+
+ def break_dirstate(self, tree):
+ """Write garbage into the dirstate file."""
if getattr(tree, 'current_dirstate', None) is None:
raise tests.TestNotApplicable(
'Only applies to dirstate-based trees')
- self.break_dirstate(tree)
- return tree
-
- def break_dirstate(self, tree):
- """Write garbage into the dirstate file."""
tree.lock_read()
try:
dirstate = tree.current_dirstate()
@@ -82,3 +83,9 @@
self.assertEqual(None, tree.path2id('baz'))
self.failIfExists('tree/foo')
self.failUnlessExists('tree/baz')
+
+ def test_reset_state_handles_corrupted_dirstate(self):
+ tree = self.make_branch_and_tree('tree')
+ self.break_dirstate(tree)
+ tree.reset_state()
+ tree.check_state()
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2010-12-02 10:41:05 +0000
+++ b/bzrlib/workingtree_4.py 2011-01-24 23:58:57 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2010 Canonical Ltd
+# Copyright (C) 2007-2011 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -1293,6 +1293,27 @@
self._inventory = inv
self.flush()
+ @needs_tree_write_lock
+ def reset_state(self, revision_ids=None):
+ """Reset the state of the working tree.
+
+ This does a hard-reset to a last-known-good state. This is a way to
+ fix if something got corrupted (like the .bzr/checkout/dirstate file)
+ """
+ if revision_ids is None:
+ revision_ids = self.get_parent_ids()
+ if not revision_ids:
+ base_tree = self.branch.repository.revision_tree(
+ _mod_revision.NULL_REVISION)
+ trees = []
+ else:
+ trees = self.branch.repository.revision_trees(revision_ids)
+ base_tree = trees[0]
+ state = self.current_dirstate()
+ self.set_par
+ self._write_inventory(rt.inventory)
+ self.set_parent_ids(revision_ids)
+
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
More information about the bazaar-commits
mailing list