def test_update_workingtree(self):
     wt = self.make_branch_and_tree('br1')
     self.build_tree_contents([('br1/bla', 'original contents\n')])
     wt.add('bla', 'bla-a')
     wt.commit('bla-a')
     root_id = wt.get_root_id()
     target = wt.bzrdir.sprout('br2').open_workingtree()
     target.unversion(['bla-a'])
     target.add('bla', 'bla-b')
     target.commit('bla-b')
     target_basis = target.basis_tree()
     target_basis.lock_read()
     self.addCleanup(target_basis.unlock)
     foreign.update_workingtree_fileids(wt, target_basis)
     wt.lock_read()
     try:
         self.assertEqual(set([root_id, "bla-b"]), set(wt.all_file_ids()))
     finally:
         wt.unlock()
示例#2
0
 def test_update_workingtree(self):
     wt = self.make_branch_and_tree('br1')
     self.build_tree_contents([('br1/bla', 'original contents\n')])
     wt.add('bla', 'bla-a')
     wt.commit('bla-a')
     root_id = wt.get_root_id()
     target = wt.bzrdir.sprout('br2').open_workingtree()
     target.unversion(['bla-a'])
     target.add('bla', 'bla-b')
     target.commit('bla-b')
     target_basis = target.basis_tree()
     target_basis.lock_read()
     self.addCleanup(target_basis.unlock)
     foreign.update_workingtree_fileids(wt, target_basis)
     wt.lock_read()
     try:
         self.assertEquals(set([root_id, "bla-b"]), set(wt.all_file_ids()))
     finally:
         wt.unlock()
示例#3
0
    def run(self, new_base=None, verbose=False, idmap_file=None, directory="."):
        from bzrlib import urlutils
        from bzrlib.branch import Branch
        from bzrlib.workingtree import WorkingTree
        from bzrlib.plugins.rewrite.pseudonyms import (
            find_pseudonyms,
            generate_rebase_map_from_pseudonyms,
            pseudonyms_as_dict,
        )
        from bzrlib.plugins.rewrite.upgrade import create_deterministic_revid, upgrade_branch
        from bzrlib.foreign import update_workingtree_fileids

        try:
            wt_to = WorkingTree.open(directory)
            branch_to = wt_to.branch
        except NoWorkingTree:
            wt_to = None
            branch_to = Branch.open(directory)

        stored_loc = branch_to.get_parent()
        if new_base is None:
            if stored_loc is None:
                raise BzrCommandError(gettext("No pull location known or" " specified."))
            else:
                display_url = urlutils.unescape_for_display(stored_loc, self.outf.encoding)
                self.outf.write(gettext("Using saved location: %s\n") % display_url)
                new_base = Branch.open(stored_loc)
        else:
            new_base = Branch.open(new_base)

        branch_to.repository.fetch(new_base.repository, revision_id=branch_to.last_revision())

        pseudonyms = pseudonyms_as_dict(find_pseudonyms(branch_to.repository, branch_to.repository.all_revision_ids()))

        def generate_rebase_map(revision_id):
            return generate_rebase_map_from_pseudonyms(
                pseudonyms,
                branch_to.repository.get_ancestry(revision_id),
                branch_to.repository.get_ancestry(new_base.last_revision()),
            )

        def determine_new_revid(old_revid, new_parents):
            return create_deterministic_revid(old_revid, new_parents)

        branch_to.lock_write()
        try:
            graph = branch_to.repository.get_graph()
            renames = upgrade_branch(
                branch_to, generate_rebase_map, determine_new_revid, allow_changes=True, verbose=verbose
            )
            if wt_to is not None:
                basis_tree = wt_to.basis_tree()
                basis_tree.lock_read()
                try:
                    update_workingtree_fileids(wt_to, basis_tree)
                finally:
                    basis_tree.unlock()
        finally:
            branch_to.unlock()

        if renames == {}:
            note(gettext("Nothing to do."))

        if idmap_file is not None:
            f = open(idmap_file, "w")
            try:
                for oldid, newid in renames.iteritems():
                    f.write("%s\t%s\n" % (oldid, newid))
            finally:
                f.close()

        if wt_to is not None:
            wt_to.set_last_revision(branch_to.last_revision())