~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-08 11:34:59 UTC
  • mfrom: (5837 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5844.
  • Revision ID: jelmer@samba.org-20110508113459-ndkbpjdb8amgq7mb
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
592
592
 
593
593
            # The dirblock has been updated
594
594
            self.assertEqual(st.st_size, entry[1][0][2])
595
 
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
595
            self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
596
596
                             state._dirblock_state)
597
597
 
598
598
            del entry
625
625
            sha1sum = dirstate.update_entry(state, entry, 'a-file', st)
626
626
            self.assertEqual('ecc5374e9ed82ad3ea3b4d452ea995a5fd3e70e3',
627
627
                             sha1sum)
628
 
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
628
            self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
629
629
                             state._dirblock_state)
630
630
 
631
631
            # Now, before we try to save, grab another dirstate, and take out a
1339
1339
            tree1.unlock()
1340
1340
 
1341
1341
 
 
1342
class TestDirStateHashUpdates(TestCaseWithDirState):
 
1343
 
 
1344
    def do_update_entry(self, state, path):
 
1345
        entry = state._get_entry(0, path_utf8=path)
 
1346
        stat = os.lstat(path)
 
1347
        return dirstate.update_entry(state, entry, os.path.abspath(path), stat)
 
1348
 
 
1349
    def test_worth_saving_limit_avoids_writing(self):
 
1350
        tree = self.make_branch_and_tree('.')
 
1351
        self.build_tree(['c', 'd'])
 
1352
        tree.lock_write()
 
1353
        tree.add(['c', 'd'], ['c-id', 'd-id'])
 
1354
        tree.commit('add c and d')
 
1355
        state = InstrumentedDirState.on_file(tree.current_dirstate()._filename,
 
1356
                                             worth_saving_limit=2)
 
1357
        tree.unlock()
 
1358
        state.lock_write()
 
1359
        self.addCleanup(state.unlock)
 
1360
        state._read_dirblocks_if_needed()
 
1361
        state.adjust_time(+20) # Allow things to be cached
 
1362
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
 
1363
                         state._dirblock_state)
 
1364
        f = open(state._filename, 'rb')
 
1365
        try:
 
1366
            content = f.read()
 
1367
        finally:
 
1368
            f.close()
 
1369
        self.do_update_entry(state, 'c')
 
1370
        self.assertEqual(1, len(state._known_hash_changes))
 
1371
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1372
                         state._dirblock_state)
 
1373
        state.save()
 
1374
        # It should not have set the state to IN_MEMORY_UNMODIFIED because the
 
1375
        # hash values haven't been written out.
 
1376
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1377
                         state._dirblock_state)
 
1378
        self.assertFileEqual(content, state._filename)
 
1379
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1380
                         state._dirblock_state)
 
1381
        self.do_update_entry(state, 'd')
 
1382
        self.assertEqual(2, len(state._known_hash_changes))
 
1383
        state.save()
 
1384
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
 
1385
                         state._dirblock_state)
 
1386
        self.assertEqual(0, len(state._known_hash_changes))
 
1387
 
 
1388
 
1342
1389
class TestGetLines(TestCaseWithDirState):
1343
1390
 
1344
1391
    def test_get_line_with_2_rows(self):
1737
1784
class InstrumentedDirState(dirstate.DirState):
1738
1785
    """An DirState with instrumented sha1 functionality."""
1739
1786
 
1740
 
    def __init__(self, path, sha1_provider):
1741
 
        super(InstrumentedDirState, self).__init__(path, sha1_provider)
 
1787
    def __init__(self, path, sha1_provider, worth_saving_limit=0):
 
1788
        super(InstrumentedDirState, self).__init__(path, sha1_provider,
 
1789
            worth_saving_limit=worth_saving_limit)
1742
1790
        self._time_offset = 0
1743
1791
        self._log = []
1744
1792
        # member is dynamically set in DirState.__init__ to turn on trace