Rev 2473: Fix test_inv - make setting WorkingTree4._dirty use a helper to reduce code duplication, and reset the inventory when we dont manually update it, if it exists. in http://bazaar.launchpad.net/~bzr/bzr/dirstate
Robert Collins
robertc at robertcollins.net
Thu Mar 1 08:02:17 GMT 2007
At http://bazaar.launchpad.net/~bzr/bzr/dirstate
------------------------------------------------------------
revno: 2473
revision-id: robertc at robertcollins.net-20070301080114-dt6xpp7v0envbati
parent: robertc at robertcollins.net-20070301074339-34mc7tfym7o4uugf
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Thu 2007-03-01 19:01:14 +1100
message:
Fix test_inv - make setting WorkingTree4._dirty use a helper to reduce code duplication, and reset the inventory when we dont manually update it, if it exists.
modified:
bzrlib/tests/test_inv.py testinv.py-20050722220913-1dc326138d1a5892
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py 2007-03-01 05:01:53 +0000
+++ b/bzrlib/tests/test_inv.py 2007-03-01 08:01:14 +0000
@@ -304,6 +304,8 @@
self.file_1 = self.inv_1['fileid']
self.file_1b = self.inv_1['binfileid']
self.tree_2 = self.wt
+ self.tree_2.lock_read()
+ self.addCleanup(self.tree_2.unlock)
self.inv_2 = self.tree_2.read_working_inventory()
self.file_2 = self.inv_2['fileid']
self.file_2b = self.inv_2['binfileid']
@@ -502,6 +504,8 @@
self.wt.add_parent_tree_id('B')
self.wt.commit('merge in B', rev_id='D')
self.inv_D = self.branch.repository.get_inventory('D')
+ self.wt.lock_read()
+ self.addCleanup(self.wt.unlock)
self.file_active = self.wt.inventory['fileid']
self.weave = self.branch.repository.weave_store.get_weave('fileid',
self.branch.repository.get_transaction())
@@ -602,10 +606,13 @@
def test_dangling_id(self):
wt = self.make_branch_and_tree('b1')
+ wt.lock_tree_write()
+ self.addCleanup(wt.unlock)
self.assertEqual(len(wt.inventory), 1)
open('b1/a', 'wb').write('a test\n')
wt.add('a')
self.assertEqual(len(wt.inventory), 2)
+ wt.flush() # workaround revert doing wt._write_inventory for now.
os.unlink('b1/a')
wt.revert([])
self.assertEqual(len(wt.inventory), 1)
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-03-01 07:27:36 +0000
+++ b/bzrlib/workingtree_4.py 2007-03-01 08:01:14 +0000
@@ -178,7 +178,17 @@
# - on the first access it will be gathered, and we can
# always change this once tests are all passing.
state.add(f, file_id, kind, None, '')
+ self._make_dirty(reset_inventory=True)
+
+ def _make_dirty(self, reset_inventory):
+ """Make the tree state dirty.
+
+ :param reset_inventory: True if the cached inventory should be removed
+ (presuming there is one).
+ """
self._dirty = True
+ if reset_inventory and self._inventory is not None:
+ self._inventory = None
def break_lock(self):
"""Break a lock if one is present from another instance.
@@ -655,7 +665,7 @@
raise
result.append((from_rel, to_rel))
state._dirblock_state = dirstate.DirState.IN_MEMORY_MODIFIED
- self._dirty = True
+ self._make_dirty(reset_inventory=False)
return result
@@ -906,13 +916,14 @@
self.branch.repository.revision_tree(None)))
ghosts.append(rev_id)
dirstate.set_parent_trees(real_trees, ghosts=ghosts)
- self._dirty = True
+ self._make_dirty(reset_inventory=False)
def _set_root_id(self, file_id):
"""See WorkingTree.set_root_id."""
state = self.current_dirstate()
state.set_path_id('', file_id)
- self._dirty = state._dirblock_state == dirstate.DirState.IN_MEMORY_MODIFIED
+ if state._dirblock_state == dirstate.DirState.IN_MEMORY_MODIFIED:
+ self._make_dirty(reset_inventory=True)
def unlock(self):
"""Unlock in format 4 trees needs to write the entire dirstate."""
@@ -1008,7 +1019,7 @@
block_index += 1
if ids_to_unversion:
raise errors.NoSuchId(self, iter(ids_to_unversion).next())
- self._dirty = True
+ self._make_dirty(reset_inventory=False)
# have to change the legacy inventory too.
if self._inventory is not None:
for file_id in file_ids:
@@ -1019,10 +1030,13 @@
"""Write inventory as the current inventory."""
assert not self._dirty, "attempting to write an inventory when the dirstate is dirty will cause data loss"
self.current_dirstate().set_state_from_inventory(inv)
- self._dirty = True
+ self._make_dirty(reset_inventory=False)
+ if self._inventory is not None:
+ self._inventory = inv
self.flush()
+
class WorkingTreeFormat4(WorkingTreeFormat3):
"""The first consolidated dirstate working tree format.
More information about the bazaar-commits
mailing list