/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

Merge bzr.dev.

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
            tree._dirstate._validate()
 
746
            # this used to cause it to lose its hashcache
 
747
            tree._dirstate.set_state_from_inventory(inv)
 
748
            tree._dirstate._validate()
 
749
        finally:
 
750
            tree.unlock()
 
751
 
 
752
        tree.lock_read()
 
753
        try:
 
754
            # now check that the state still has the original hashcache value
 
755
            state = tree._dirstate
 
756
            state._validate()
 
757
            foo_tuple = state._get_entry(0, path_utf8='foo')
 
758
            self.assertEqual(
 
759
                (('', 'foo', 'foo-id',),
 
760
                 [('f', foo_sha, len(foo_contents), False,
 
761
                   dirstate.pack_stat(foo_stat))]),
 
762
                foo_tuple)
 
763
        finally:
 
764
            tree.unlock()
 
765
 
 
766
 
703
767
    def test_set_state_from_inventory_mixed_paths(self):
704
768
        tree1 = self.make_branch_and_tree('tree1')
705
769
        self.build_tree(['tree1/a/', 'tree1/a/b/', 'tree1/a-b/',
1399
1463
        super(InstrumentedDirState, self).__init__(path)
1400
1464
        self._time_offset = 0
1401
1465
        self._log = []
 
1466
        # member is dynamically set in DirState.__init__ to turn on trace
 
1467
        self._sha1_file = self._sha1_file_and_log
1402
1468
 
1403
1469
    def _sha_cutoff_time(self):
1404
1470
        timestamp = super(InstrumentedDirState, self)._sha_cutoff_time()
1405
1471
        self._cutoff_time = timestamp + self._time_offset
1406
1472
 
1407
 
    def _sha1_file(self, abspath, entry):
 
1473
    def _sha1_file_and_log(self, abspath):
1408
1474
        self._log.append(('sha1', abspath))
1409
 
        return super(InstrumentedDirState, self)._sha1_file(abspath, entry)
 
1475
        return osutils.sha_file_by_name(abspath)
1410
1476
 
1411
1477
    def _read_link(self, abspath, old_link):
1412
1478
        self._log.append(('read_link', abspath, old_link))