def test_revision_history_when_unlocked(self): """Repeated calls to revision history will call _gen_revision_history each time when the branch is not locked. """ branch, calls = self.get_instrumented_branch() # Repeatedly call revision_history. branch.revision_history() branch.revision_history() self.assertEqual( ['_gen_revision_history', '_gen_revision_history'], calls)
def test_set_revision_history_when_unlocked(self): """When the branch is not locked, calling set_revision_history will not cause the revision history to be cached. """ branch, calls = self.get_instrumented_branch() # Lock the branch, set the revision history, then repeatedly call # revision_history. branch.set_revision_history([]) branch.revision_history() self.assertEqual(['_gen_revision_history'], calls)
def test_revision_history_when_unlocked(self): """Repeated calls to revision history will call _gen_revision_history each time when the branch is not locked. """ branch, calls = self.get_instrumented_branch() # Repeatedly call revision_history. branch.revision_history() branch.revision_history() self.assertEqual(['_gen_revision_history', '_gen_revision_history'], calls)
def test_revision_history_when_locked(self): """Repeated calls to revision history will only call _gen_revision_history once while the branch is locked. """ branch, calls = self.get_instrumented_branch() # Lock the branch, then repeatedly call revision_history. branch.lock_read() try: branch.revision_history() branch.revision_history() self.assertEqual(['_gen_revision_history'], calls) finally: branch.unlock()
def test_set_revision_history_when_locked(self): """When the branch is locked, calling set_revision_history should cache the revision history so that a later call to revision_history will not need to call _gen_revision_history. """ branch, calls = self.get_instrumented_branch() # Lock the branch, set the revision history, then repeatedly call # revision_history. branch.lock_write() branch.set_revision_history([]) try: branch.revision_history() self.assertEqual([], calls) finally: branch.unlock()
def test_upgrade_v6_to_meta_no_workingtree(self): # Some format6 branches do not have checkout files. Upgrading # such a branch to metadir must not setup a working tree. self.build_tree_contents(_upgrade1_template) upgrade('.', bzrdir.BzrDirFormat6()) transport = get_transport('.') transport.delete_multi(['.bzr/pending-merges', '.bzr/inventory']) self.assertFalse(transport.has('.bzr/stat-cache')) # XXX: upgrade fails if a backup.bzr is already present # -- David Allouche 2006-08-11 transport.delete_tree('backup.bzr') # At this point, we have a format6 branch without checkout files. upgrade('.', bzrdir.BzrDirMetaFormat1()) # The upgrade should not have set up a working tree. control = bzrdir.BzrDir.open('.') self.assertFalse(control.has_workingtree()) # We have covered the scope of this test, we may as well check that # upgrade has not eaten our data, even if it's a bit redundant with # other tests. self.failUnless(isinstance(control._format, bzrdir.BzrDirMetaFormat1)) branch = control.open_branch() self.assertEquals(branch.revision_history(), [ '[email protected]', '[email protected]' ])
def test_cached_revision_history_not_accidentally_mutable(self): """When there's a cached version of the history, revision_history returns a copy of the cached data so that callers cannot accidentally corrupt the cache. """ branch = self.get_branch() # Lock the branch, then repeatedly call revision_history, mutating the # results. branch.lock_read() try: # The first time the data returned will not be in the cache. history = branch.revision_history() history.append('one') # The second time the data comes from the cache. history = branch.revision_history() history.append('two') # The revision_history() should still be unchanged, even though # we've mutated the return values from earlier calls. self.assertEqual([], branch.revision_history()) finally: branch.unlock()
def test_upgrade_v6_to_meta_no_workingtree(self): # Some format6 branches do not have checkout files. Upgrading # such a branch to metadir must not setup a working tree. self.build_tree_contents(_upgrade1_template) upgrade('.', bzrdir.BzrDirFormat6()) transport = get_transport('.') transport.delete_multi(['.bzr/pending-merges', '.bzr/inventory']) self.assertFalse(transport.has('.bzr/stat-cache')) # XXX: upgrade fails if a backup.bzr is already present # -- David Allouche 2006-08-11 transport.delete_tree('backup.bzr') # At this point, we have a format6 branch without checkout files. upgrade('.', bzrdir.BzrDirMetaFormat1()) # The upgrade should not have set up a working tree. control = bzrdir.BzrDir.open('.') self.assertFalse(control.has_workingtree()) # We have covered the scope of this test, we may as well check that # upgrade has not eaten our data, even if it's a bit redundant with # other tests. self.failUnless(isinstance(control._format, bzrdir.BzrDirMetaFormat1)) branch = control.open_branch() self.assertEquals(branch.revision_history(), ['[email protected]', '[email protected]'])