def test_has_tree_references(self): """Detects whether repo contains actual tree references.""" self.useBzrBranches(direct_database=True) format = format_registry.make_bzrdir('pack-0.92-subtree') branch, tree = self.create_branch_and_tree(format=format) upgrader = self.getUpgrader(tree.branch, branch) with read_locked(tree.branch.repository): self.assertFalse(upgrader.has_tree_references()) self.addTreeReference(tree) with read_locked(tree.branch.repository): self.assertTrue(upgrader.has_tree_references())
def test_add_upgraded_branch_preserves_tip(self): """Fetch-based upgrade preserves branch tip.""" upgrader = self.prepare('pack-0.92-subtree') with read_locked(upgrader.bzr_branch): upgrader.start_upgrade() upgraded = upgrader.add_upgraded_branch().open_branch() self.assertEqual('prepare-commit', upgraded.last_revision())
def finish_upgrade(self): """Create an upgraded version of self.branch in self.target_dir.""" with read_locked(self.bzr_branch): repository = self.get_bzrdir().open_repository() self.add_upgraded_branch() repository.fetch(self.bzr_branch.repository) self.swap_in() branch_changed(self.branch)
def test_add_upgraded_branch_preserves_tags(self): """Fetch-based upgrade preserves heads in the repository.""" upgrader = self.prepare('pack-0.92-subtree') upgrader.bzr_branch.tags.set_tag('steve', 'rev-id') with read_locked(upgrader.bzr_branch): upgrader.start_upgrade() upgraded = upgrader.add_upgraded_branch().open_branch() self.assertEqual('rev-id', upgraded.tags.lookup_tag('steve'))
def test_create_upgraded_repository_preserves_dead_heads(self): """Fetch-based upgrade preserves heads in the repository.""" upgrader = self.prepare('pack-0.92-subtree') upgrader.bzr_branch.set_last_revision_info(0, NULL_REVISION) with read_locked(upgrader.bzr_branch): upgrader.create_upgraded_repository() upgraded = upgrader.get_bzrdir().open_repository() self.assertEqual('foo', upgraded.get_revision('prepare-commit').message)
def test_subtree_format_repo_format(self): """Even subtree formats use 2a if they don't have tree references.""" self.useBzrBranches(direct_database=True) format = format_registry.make_bzrdir('pack-0.92-subtree') branch, tree = self.create_branch_and_tree(format=format) upgrader = self.getUpgrader(tree.branch, branch) with read_locked(upgrader.bzr_branch): target_format = upgrader.get_target_format() self.assertIs(target_format._repository_format.__class__, RepositoryFormat2a)
def test_tree_reference_repo_format(self): """Repos with tree references get 2aSubtree.""" self.useBzrBranches(direct_database=True) format = format_registry.make_bzrdir('pack-0.92-subtree') branch, tree = self.create_branch_and_tree(format=format) upgrader = self.getUpgrader(tree.branch, branch) self.addTreeReference(tree) with read_locked(upgrader.bzr_branch): target_format = upgrader.get_target_format() self.assertIs(target_format._repository_format.__class__, RepositoryFormat2aSubtree)
def run(self): """Send all the emails about all the added revisions.""" diff_levels = (BranchSubscriptionNotificationLevel.DIFFSONLY, BranchSubscriptionNotificationLevel.FULL) subscriptions = self.branch.getSubscriptionsByLevel(diff_levels) if not subscriptions: return with server(get_ro_server(), no_replace=True): with read_locked(self.bzr_branch): for revision, revno in self.iterAddedMainline(): assert revno is not None mailer = self.getMailerForRevision( revision, revno, self.generateDiffs()) mailer.sendAll()
def test_use_subtree_format_for_tree_references(self): """Subtree references cause RepositoryFormat2aSubtree to be used.""" self.useBzrBranches(direct_database=True) format = format_registry.make_bzrdir('pack-0.92-subtree') branch, tree = self.create_branch_and_tree(format=format) sub_branch = BzrDir.create_branch_convenience( tree.bzrdir.root_transport.clone('sub').base, format=format) tree.add_reference(sub_branch.bzrdir.open_workingtree()) tree.commit('added tree reference', committer='*****@*****.**') upgrader = self.getUpgrader(tree.branch, branch) with read_locked(tree.branch): upgrader.create_upgraded_repository() upgraded = upgrader.get_bzrdir().open_repository() self.assertIs(RepositoryFormat2aSubtree, upgraded._format.__class__)
def test_ancestry_already_present(self): # If a BranchRevision is being added, and it's already in the DB, but # not found through the graph operations, we should schedule it for # deletion anyway. rev1_id = self.bzr_tree.commit("initial commit", committer="*****@*****.**") merge_tree = self.bzr_tree.bzrdir.sprout("merge").open_workingtree() merge_id = merge_tree.commit("mergeable commit", committer="*****@*****.**") self.bzr_tree.merge_from_branch(merge_tree.branch) rev2_id = self.bzr_tree.commit("merge", committer="*****@*****.**") self.useContext(read_locked(self.bzr_tree)) syncer = BzrSync(self.db_branch) syncer.syncBranchAndClose(self.bzr_tree.branch) self.assertEqual(rev2_id, self.db_branch.last_scanned_id) self.db_branch.last_scanned_id = rev1_id db_ancestry, db_history = self.db_branch.getScannerData() branchrevisions_to_delete = syncer.planDatabaseChanges( self.bzr_branch, [rev1_id, rev2_id], db_ancestry, db_history )[1] self.assertIn(merge_id, branchrevisions_to_delete)
def test_ancestry_already_present(self): # If a BranchRevision is being added, and it's already in the DB, but # not found through the graph operations, we should schedule it for # deletion anyway. rev1_id = self.bzr_tree.commit('initial commit', committer='*****@*****.**') merge_tree = self.bzr_tree.bzrdir.sprout('merge').open_workingtree() merge_id = merge_tree.commit('mergeable commit', committer='*****@*****.**') self.bzr_tree.merge_from_branch(merge_tree.branch) rev2_id = self.bzr_tree.commit('merge', committer='*****@*****.**') self.useContext(read_locked(self.bzr_tree)) syncer = BzrSync(self.db_branch) syncer.syncBranchAndClose(self.bzr_tree.branch) self.assertEqual(rev2_id, self.db_branch.last_scanned_id) self.db_branch.last_scanned_id = rev1_id db_ancestry, db_history = self.db_branch.getScannerData() branchrevisions_to_delete = syncer.planDatabaseChanges( self.bzr_branch, [rev1_id, rev2_id], db_ancestry, db_history)[1] self.assertIn(merge_id, branchrevisions_to_delete)
def generateIncrementalDiff(cls, old_revision, new_revision, source_branch, ignore_branches): """Return a Diff whose contents are an incremental diff. The Diff's contents will show the changes made between old_revision and new_revision, except those changes introduced by the ignore_branches. :param old_revision: The `Revision` to show changes from. :param new_revision: The `Revision` to show changes to. :param source_branch: The bzr branch containing these revisions. :param ignore_brances: A collection of branches to ignore merges from. :return: a `Diff`. """ diff_content = StringIO() read_locks = [read_locked(branch) for branch in [source_branch] + ignore_branches] with nested(*read_locks): diff_ignore_branches( source_branch, ignore_branches, old_revision.revision_id, new_revision.revision_id, diff_content) return cls.fromFileAtEnd(diff_content)
def start_upgrade(self): """Do the slow part of the upgrade process.""" if os.path.exists(self.target_subdir): raise AlreadyUpgraded with read_locked(self.bzr_branch): self.create_upgraded_repository()
def test_create_upgraded_repository_uses_target_subdir(self): """The repository is created in the right place.""" upgrader = self.prepare() with read_locked(upgrader.bzr_branch): upgrader.create_upgraded_repository() upgrader.get_bzrdir().open_repository()