598
598
def get_tree_with_cachable_file_foo(self):
599
599
tree = self.make_branch_and_tree('.')
600
self.build_tree(['foo'])
601
self.addCleanup(tree.unlock)
602
self.build_tree_contents([('foo', 'a bit of content for foo\n')])
601
603
tree.add(['foo'], ['foo-id'])
602
# a 4 second old timestamp is always hashable - sucks to delay
603
# the test suite, but not testing this is worse.
604
tree.current_dirstate()._cutoff_time = time.time() + 60
607
607
def test_commit_updates_hash_cache(self):
608
608
tree = self.get_tree_with_cachable_file_foo()
609
609
revid = tree.commit('a commit')
610
610
# tree's dirstate should now have a valid stat entry for foo.
612
self.addCleanup(tree.unlock)
613
611
entry = tree._get_entry(path='foo')
614
612
expected_sha1 = osutils.sha_file_by_name('foo')
615
613
self.assertEqual(expected_sha1, entry[1][0][1])
614
self.assertEqual(len('a bit of content for foo\n'), entry[1][0][2])
617
616
def test_observed_sha1_cachable(self):
618
617
tree = self.get_tree_with_cachable_file_foo()
619
618
expected_sha1 = osutils.sha_file_by_name('foo')
620
619
statvalue = os.lstat("foo")
623
tree._observed_sha1("foo-id", "foo", (expected_sha1, statvalue))
624
self.assertEqual(expected_sha1,
625
tree._get_entry(path="foo")[1][0][1])
620
tree._observed_sha1("foo-id", "foo", (expected_sha1, statvalue))
621
entry = tree._get_entry(path="foo")
622
entry_state = entry[1][0]
623
self.assertEqual(expected_sha1, entry_state[1])
624
self.assertEqual(statvalue.st_size, entry_state[2])
628
627
tree = tree.bzrdir.open_workingtree()
630
629
self.addCleanup(tree.unlock)
631
self.assertEqual(expected_sha1, tree._get_entry(path="foo")[1][0][1])
630
entry = tree._get_entry(path="foo")
631
entry_state = entry[1][0]
632
self.assertEqual(expected_sha1, entry_state[1])
633
self.assertEqual(statvalue.st_size, entry_state[2])
633
635
def test_observed_sha1_new_file(self):
634
636
tree = self.make_branch_and_tree('.')