def test_compare_calls_InterTree_compare(self): """This test tests the way Tree.compare() uses InterTree.""" old_optimisers = InterTree._optimisers try: InterTree._optimisers = [] RecordingOptimiser.calls = [] InterTree.register_optimiser(RecordingOptimiser) tree = self.make_branch_and_tree('1') tree2 = self.make_branch_and_tree('2') # do a series of calls: # trivial usage tree.changes_from(tree2) # pass in all optional arguments by position tree.changes_from(tree2, 'unchanged', 'specific', 'extra', 'require', True) # pass in all optional arguments by keyword tree.changes_from(tree2, specific_files='specific', want_unchanged='unchanged', extra_trees='extra', require_versioned='require', include_root=True, want_unversioned=True, ) finally: InterTree._optimisers = old_optimisers self.assertEqual( [ ('compare', tree2, tree, False, None, None, False, False, False), ('compare', tree2, tree, 'unchanged', 'specific', 'extra', 'require', True, False), ('compare', tree2, tree, 'unchanged', 'specific', 'extra', 'require', True, True), ], RecordingOptimiser.calls)
def test_working_tree_working_tree(self): # we should have an InterTree available for WorkingTree to # WorkingTree. tree = self.make_branch_and_tree('1') tree2 = self.make_branch_and_tree('2') optimiser = InterTree.get(tree, tree2) self.assertIsInstance(optimiser, InterTree) optimiser = InterTree.get(tree2, tree) self.assertIsInstance(optimiser, InterTree)
def test_working_tree_revision_tree(self): # we should have an InterTree available for WorkingTree to # RevisionTree. tree = self.make_branch_and_tree('.') rev_id = tree.commit('first post') rev_tree = tree.branch.repository.revision_tree(rev_id) optimiser = InterTree.get(rev_tree, tree) self.assertIsInstance(optimiser, InterTree) optimiser = InterTree.get(tree, rev_tree) self.assertIsInstance(optimiser, InterTree)
def test_revision_tree_revision_tree(self): # we should have an InterTree registered for RevisionTree to # RevisionTree. tree = self.make_branch_and_tree('.') rev_id = tree.commit('first post') rev_id2 = tree.commit('second post', allow_pointless=True) rev_tree = tree.branch.repository.revision_tree(rev_id) rev_tree2 = tree.branch.repository.revision_tree(rev_id2) optimiser = InterTree.get(rev_tree, rev_tree2) self.assertIsInstance(optimiser, InterTree) optimiser = InterTree.get(rev_tree2, rev_tree) self.assertIsInstance(optimiser, InterTree)
def test_revtree_not_in_dirstate_to_dirstate_not_interdirstate(self): # we should not get a dirstate optimiser when the revision id for of # the source is not in the dirstate of the target. tree = self.make_workingtree() rev_id = tree.commit('first post') rev_id2 = tree.commit('second post') rev_tree = tree.branch.repository.revision_tree(rev_id) tree.lock_read() optimiser = InterTree.get(rev_tree, tree) self.assertIsInstance(optimiser, InterTree) self.assertFalse(isinstance(optimiser, workingtree_4.InterDirStateTree)) optimiser = InterTree.get(tree, rev_tree) self.assertIsInstance(optimiser, InterTree) self.assertFalse(isinstance(optimiser, workingtree_4.InterDirStateTree)) tree.unlock()
def test_revtree_to_revtree_not_interdirstate(self): # we should not get a dirstate optimiser for two repository sourced # revtrees. we can't prove a negative, so we dont do exhaustive tests # of all formats; though that could be written in the future it doesn't # seem well worth it. tree = self.make_workingtree() rev_id = tree.commit('first post') rev_id2 = tree.commit('second post') rev_tree = tree.branch.repository.revision_tree(rev_id) rev_tree2 = tree.branch.repository.revision_tree(rev_id2) optimiser = InterTree.get(rev_tree, rev_tree2) self.assertIsInstance(optimiser, InterTree) self.assertFalse(isinstance(optimiser, workingtree_4.InterDirStateTree)) optimiser = InterTree.get(rev_tree2, rev_tree) self.assertIsInstance(optimiser, InterTree) self.assertFalse(isinstance(optimiser, workingtree_4.InterDirStateTree))
def get_file_items(self, window, files): items = [] trees = {} try: for vfs_file in files: controldir, path = self._open_bzrdir(vfs_file) try: tree = trees[controldir.user_url] except KeyError: try: tree = controldir.open_workingtree() except NoWorkingTree: continue trees[controldir.user_url] = tree tree.lock_read() nautilus_integration = self.check_branch_enabled(tree.branch) if not nautilus_integration: continue intertree = InterTree.get(tree.basis_tree(), tree) items.extend(list(self._get_file_menuitems(tree, intertree, path))) finally: for tree in trees.itervalues(): tree.unlock() return items
def update_file_info(self, vfs_file): try: controldir, path = self._open_bzrdir(vfs_file) except NotBranchError: return try: tree = controldir.open_workingtree() except NoWorkingTree: return tree.lock_read() try: nautilus_integration = self.check_branch_enabled(tree.branch) if not nautilus_integration: return basis_tree = tree.basis_tree() intertree = InterTree.get(basis_tree, tree) basis_tree.lock_read() try: (status, emblem, file_revision) = self._file_summary(tree, basis_tree, intertree, path) finally: basis_tree.unlock() if emblem is not None: vfs_file.add_emblem(emblem) vfs_file.add_string_attribute('bzr_status', status) vfs_file.add_string_attribute('bzr_revision', file_revision) finally: tree.unlock()
def test_empty_basis_revtree_to_dirstate_tree(self): # we should get a InterDirStateTree for doing # 'changes_from' from an empty repository based rev tree to a # WorkingTree4. tree = self.make_workingtree() tree.lock_read() basis_tree = tree.branch.repository.revision_tree(tree.last_revision()) basis_tree.lock_read() optimiser = InterTree.get(basis_tree, tree) tree.unlock() basis_tree.unlock() self.assertIsInstance(optimiser, workingtree_4.InterDirStateTree)
def test_empty_basis_to_dirstate_tree(self): # we should get a InterDirStateTree for doing # 'changes_from' from the first basis dirstate revision tree to a # WorkingTree4. tree = self.make_workingtree() tree.lock_read() basis_tree = tree.basis_tree() basis_tree.lock_read() optimiser = InterTree.get(basis_tree, tree) tree.unlock() basis_tree.unlock() self.assertIsInstance(optimiser, workingtree_4.InterDirStateTree)
def test_tree_to_basis_in_other_tree(self): # we should get a InterDirStateTree when # the source revid is in the dirstate object of the target and # the dirstates are different. This is largely covered by testing # with repository revtrees, so is just for extra confidence. tree = self.make_workingtree('a') tree.commit('first post') tree2 = self.make_workingtree('b') tree2.pull(tree.branch) basis_tree = tree.basis_tree() tree2.lock_read() basis_tree.lock_read() optimiser = InterTree.get(basis_tree, tree2) tree2.unlock() basis_tree.unlock() self.assertIsInstance(optimiser, workingtree_4.InterDirStateTree)
def test_merged_revtree_to_tree(self): # we should get a InterDirStateTree when # the source tree is a merged tree present in the dirstate of target. tree = self.make_workingtree('a') tree.commit('first post') tree.commit('tree 1 commit 2') tree2 = self.make_workingtree('b') tree2.pull(tree.branch) tree2.commit('tree 2 commit 2') tree.merge_from_branch(tree2.branch) second_parent_tree = tree.revision_tree(tree.get_parent_ids()[1]) second_parent_tree.lock_read() tree.lock_read() optimiser = InterTree.get(second_parent_tree, tree) tree.unlock() second_parent_tree.unlock() self.assertIsInstance(optimiser, workingtree_4.InterDirStateTree)