700
700
# This will unlock it
701
701
self.check_state_with_reopen(expected_result, state)
703
def test_set_state_from_inventory_preserves_hashcache(self):
704
# https://bugs.launchpad.net/bzr/+bug/146176
705
# set_state_from_inventory should preserve the stat and hash value for
706
# workingtree files that are not changed by the inventory.
708
tree = self.make_branch_and_tree('.')
709
# depends on the default format using dirstate...
712
# make a dirstate with some valid hashcache data
713
# file on disk, but that's not needed for this test
714
foo_contents = 'contents of foo'
715
self.build_tree_contents([('foo', foo_contents)])
716
tree.add('foo', 'foo-id')
718
foo_stat = os.stat('foo')
719
foo_packed = dirstate.pack_stat(foo_stat)
720
foo_sha = osutils.sha_string(foo_contents)
721
foo_size = len(foo_contents)
723
# should not be cached yet, because the file's too fresh
725
(('', 'foo', 'foo-id',),
726
[('f', '', 0, False, dirstate.DirState.NULLSTAT)]),
727
tree._dirstate._get_entry(0, 'foo-id'))
728
# poke in some hashcache information - it wouldn't normally be
729
# stored because it's too fresh
730
tree._dirstate.update_minimal(
731
('', 'foo', 'foo-id'),
732
'f', False, foo_sha, foo_packed, foo_size, 'foo')
733
# now should be cached
735
(('', 'foo', 'foo-id',),
736
[('f', foo_sha, foo_size, False, foo_packed)]),
737
tree._dirstate._get_entry(0, 'foo-id'))
739
# extract the inventory, and add something to it
740
inv = tree._get_inventory()
741
# should see the file we poked in...
742
self.assertTrue(inv.has_id('foo-id'))
743
self.assertTrue(inv.has_filename('foo'))
744
inv.add_path('bar', 'file', 'bar-id')
745
# this used to cause it to lose its hashcache
746
tree._dirstate.set_state_from_inventory(inv)
752
# now check that the state still has the original hashcache value
753
state = tree._dirstate
754
foo_tuple = state._get_entry(0, path_utf8='foo')
756
(('', 'foo', 'foo-id',),
757
[('f', foo_sha, len(foo_contents), False,
758
dirstate.pack_stat(foo_stat))]),
703
764
def test_set_state_from_inventory_mixed_paths(self):
704
765
tree1 = self.make_branch_and_tree('tree1')
705
766
self.build_tree(['tree1/a/', 'tree1/a/b/', 'tree1/a-b/',