~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-09 08:08:20 UTC
  • mfrom: (2872.4.11 146176-dirstate)
  • Revision ID: pqm@pqm.ubuntu.com-20071009080820-civ61gexahohpats
Fix incorrect comparison in Dirstate.set_state_from_inventory, and bug #146176

Show diffs side-by-side

added added

removed removed

Lines of Context:
700
700
            # This will unlock it
701
701
            self.check_state_with_reopen(expected_result, state)
702
702
 
 
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.
 
707
       
 
708
        tree = self.make_branch_and_tree('.')
 
709
        # depends on the default format using dirstate...
 
710
        tree.lock_write()
 
711
        try:
 
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')
 
717
 
 
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)
 
722
 
 
723
            # should not be cached yet, because the file's too fresh
 
724
            self.assertEqual(
 
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
 
734
            self.assertEqual(
 
735
                (('', 'foo', 'foo-id',),
 
736
                 [('f', foo_sha, foo_size, False, foo_packed)]),
 
737
                tree._dirstate._get_entry(0, 'foo-id'))
 
738
           
 
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)
 
747
        finally:
 
748
            tree.unlock()
 
749
 
 
750
        tree.lock_read()
 
751
        try:
 
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')
 
755
            self.assertEqual(
 
756
                (('', 'foo', 'foo-id',),
 
757
                 [('f', foo_sha, len(foo_contents), False,
 
758
                   dirstate.pack_stat(foo_stat))]),
 
759
                foo_tuple)
 
760
        finally:
 
761
            tree.unlock()
 
762
 
 
763
 
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/',