438
438
def create_branch_with_reference(self):
439
439
branch = self.make_branch('branch')
440
branch._set_all_reference_info({'path': ('location', 'file-id')})
440
branch._set_all_reference_info({'file-id': ('path', 'location')})
454
454
branch.lock_read()
455
455
self.addCleanup(branch.unlock)
456
456
self.instrument_branch(branch, gets)
457
branch.get_reference_info('path')
458
branch.get_reference_info('path')
457
branch.get_reference_info('file-id')
458
branch.get_reference_info('file-id')
459
459
self.assertEqual(1, len(gets))
461
461
def test_reference_info_caching_read_unlocked(self):
463
463
branch = self.create_branch_with_reference()
464
464
self.instrument_branch(branch, gets)
465
branch.get_reference_info('path')
466
branch.get_reference_info('path')
465
branch.get_reference_info('file-id')
466
branch.get_reference_info('file-id')
467
467
self.assertEqual(2, len(gets))
469
469
def test_reference_info_caching_write_locked(self):
472
472
branch.lock_write()
473
473
self.instrument_branch(branch, gets)
474
474
self.addCleanup(branch.unlock)
475
branch._set_all_reference_info({'path2': ('location2', 'file-id')})
476
location, file_id = branch.get_reference_info('path2')
475
branch._set_all_reference_info({'file-id': ('path2', 'location2')})
476
path, location = branch.get_reference_info('file-id')
477
477
self.assertEqual(0, len(gets))
478
self.assertEqual('file-id', file_id)
478
self.assertEqual('path2', path)
479
479
self.assertEqual('location2', location)
481
481
def test_reference_info_caches_cleared(self):
482
482
branch = self.make_branch('branch')
483
with branch.lock_write():
484
branch.set_reference_info('path2', 'location2', b'file-id')
484
branch.set_reference_info('file-id', 'path2', 'location2')
485
486
doppelganger = _mod_branch.Branch.open('branch')
486
doppelganger.set_reference_info('path3', 'location3', b'file-id')
487
self.assertEqual(('location3', b'file-id'),
488
branch.get_reference_info('path3'))
487
doppelganger.set_reference_info('file-id', 'path3', 'location3')
488
self.assertEqual(('path3', 'location3'),
489
branch.get_reference_info('file-id'))
490
491
def _recordParentMapCalls(self, repo):
491
492
self._parent_map_calls = []