1346
class TestDirStateHashUpdates(TestCaseWithDirState):
1348
def do_update_entry(self, state, path):
1349
entry = state._get_entry(0, path_utf8=path)
1350
stat = os.lstat(path)
1351
return dirstate.update_entry(state, entry, os.path.abspath(path), stat)
1353
def test_worth_saving_limit_avoids_writing(self):
1354
state = self.create_complex_dirstate()
1357
self.build_tree(['c', 'd'])
1358
state = InstrumentedDirState.on_file('dirstate',
1359
worth_saving_limit=2)
1361
self.addCleanup(state.unlock)
1362
state._read_dirblocks_if_needed()
1363
state.adjust_time(+20) # Allow things to be cached
1364
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1365
state._dirblock_state)
1366
f = open('dirstate', 'rb')
1371
self.do_update_entry(state, 'c')
1372
self.assertEqual(1, len(state._known_hash_changes))
1373
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
1374
state._dirblock_state)
1376
# It should not have set the state to IN_MEMORY_UNMODIFIED because the
1377
# hash values haven't been written out.
1378
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
1379
state._dirblock_state)
1380
self.assertFileEqual(content, 'dirstate')
1381
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
1382
state._dirblock_state)
1383
self.do_update_entry(state, 'd')
1384
self.assertEqual(2, len(state._known_hash_changes))
1386
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1387
state._dirblock_state)
1388
self.assertEqual(0, len(state._known_hash_changes))
1346
1390
class TestGetLines(TestCaseWithDirState):
1348
1392
def test_get_line_with_2_rows(self):
1741
1785
class InstrumentedDirState(dirstate.DirState):
1742
1786
"""An DirState with instrumented sha1 functionality."""
1744
def __init__(self, path, sha1_provider):
1745
super(InstrumentedDirState, self).__init__(path, sha1_provider)
1788
def __init__(self, path, sha1_provider, worth_saving_limit=0):
1789
super(InstrumentedDirState, self).__init__(path, sha1_provider,
1790
worth_saving_limit=worth_saving_limit)
1746
1791
self._time_offset = 0
1748
1793
# member is dynamically set in DirState.__init__ to turn on trace