Example #1
0
 def __init__(self, source, target):
     InterRepository.__init__(self, source, target)
     mapping = self.source.get_mapping()
     self._target_overlay = get_overlay(self.target, mapping)
     self._inventories = lru_cache.LRUCache(INVENTORY_CACHE_SIZE)
     self._revisions = {}
     self._files = {}
     self._text_metadata = {}
     self._symlink_targets = {}
     # Map mapping manifest ids to bzr revision ids
     self._manifest2rev_map = defaultdict(set)
Example #2
0
 def _push_helper(self, stop_revision=None, overwrite=False,
         lossy=False):
     interrepo = InterRepository(self.source.repository, self.target.repository)
     if stop_revision is None:
         stop_revision = self.source.last_revision()
     cg, revidmap = interrepo._generate_changegroup(stop_revision, self.target.mapping, lossy=lossy)
     heads = [revidmap[stop_revision]]
     remote = self.target.repository._hgrepo
     if remote.capable('unbundle'):
         remote.unbundle(cg, heads, None)
     else:
         # TODO: Set heads
         remote.addchangegroup(cg, 'push', self.source.base)
     return dict((k, self.target.mapping.revision_id_foreign_to_bzr(v)) for (k, v) in revidmap.iteritems())
Example #3
0
 def fetch(self, stop_revision=None, fetch_tags=True, limit=None):
     """See InterBranch.fetch."""
     if stop_revision is None:
         stop_revision = self.source.last_revision()
     inter = InterRepository.get(self.source.repository,
                                 self.target.repository)
     inter.fetch(revision_id=stop_revision, limit=limit)
Example #4
0
 def sprout(self,
            url,
            revision_id=None,
            force_new_repo=False,
            recurse='down',
            possible_transports=None,
            accelerator_tree=None,
            hardlink=False,
            stacked=False,
            source_branch=None,
            create_tree_if_local=True):
     from breezy.repository import InterRepository
     from breezy.transport.local import LocalTransport
     from breezy.transport import get_transport
     target_transport = get_transport(url, possible_transports)
     target_transport.ensure_base()
     cloning_format = self.cloning_metadir()
     # Create/update the result branch
     result = cloning_format.initialize_on_transport(target_transport)
     source_branch = self.open_branch()
     source_repository = self.find_repository()
     try:
         result_repo = result.find_repository()
     except errors.NoRepositoryPresent:
         result_repo = result.create_repository()
         target_is_empty = True
     else:
         target_is_empty = None  # Unknown
     if stacked:
         raise errors.IncompatibleRepositories(source_repository,
                                               result_repo)
     interrepo = InterRepository.get(source_repository, result_repo)
     interrepo.fetch(revision_id=revision_id)
     result_branch = source_branch.sprout(result,
                                          revision_id=revision_id,
                                          repository=result_repo)
     if (create_tree_if_local
             and isinstance(target_transport, LocalTransport)
             and (result_repo is None or result_repo.make_working_trees())):
         wt = result.create_workingtree(accelerator_tree=accelerator_tree,
                                        hardlink=hardlink,
                                        from_branch=result_branch)
         wt.lock_write()
         try:
             if wt.path2id('') is None:
                 try:
                     wt.set_root_id(self.open_workingtree.get_root_id())
                 except errors.NoWorkingTree:
                     pass
         finally:
             wt.unlock()
     return result
Example #5
0
 def run(self, svn_repository, directory=".", no_reconcile=False):
     from breezy.controldir import ControlDir
     from breezy.repository import InterRepository, Repository
     from breezy import trace
     correct_dir = ControlDir.open_containing(svn_repository)[0]
     correct_repo = correct_dir.find_repository()
     repo_to_fix = Repository.open(directory)
     revids = repo_to_fix.all_revision_ids()
     present_revisions = correct_repo.has_revisions(revids)
     dir_to_fix = repo_to_fix.controldir
     old_repo_format = repo_to_fix._format
     del repo_to_fix
     trace.note("Renaming existing repository to repository.backup.")
     dir_to_fix.control_transport.rename('repository', 'repository.backup')
     backup_transport = dir_to_fix.control_transport.clone(
         'repository.backup')
     old_repo = old_repo_format.open(
         dir_to_fix, _found=True, _override_transport=backup_transport)
     new_repo = dir_to_fix.create_repository(
         shared=old_repo.is_shared())
     working_trees = old_repo.make_working_trees()
     if working_trees is not None:
         new_repo.set_make_working_trees(working_trees)
     interrepo = InterRepository.get(correct_repo, new_repo)
     revisionfinder = interrepo.get_revision_finder(True)
     trace.note("Finding revisions to fetch from SVN")
     for revid in present_revisions:
         foreign_revid, mapping = correct_repo.lookup_bzr_revision_id(
             revid)
         revisionfinder.find_until(
             foreign_revid, mapping, find_ghosts=False,
             exclude_non_mainline=False)
     trace.note("Fetching correct SVN revisions")
     interrepo.fetch(needed=revisionfinder.get_missing())
     trace.note("Fetching other revisions")
     new_repo.fetch(old_repo)
     if not no_reconcile:
         from breezy.reconcile import reconcile
         trace.note("Reconciling new repository.")
         reconcile(dir_to_fix)
     trace.note('Removing backup')
     dir_to_fix.control_transport.delete_tree('repository.backup')
Example #6
0
    def sprout(self,
               url,
               revision_id=None,
               force_new_repo=False,
               recurse='down',
               possible_transports=None,
               accelerator_tree=None,
               hardlink=False,
               stacked=False,
               source_branch=None,
               create_tree_if_local=True):
        from breezy.repository import InterRepository
        from breezy.transport.local import LocalTransport
        relpath = self._determine_relpath(None)
        if relpath == u"":
            guessed_layout = self.find_repository().get_guessed_layout()
            if guessed_layout is not None and not guessed_layout.is_branch(
                    u""):
                trace.warning(
                    'Cloning Subversion repository as branch. '
                    'To import the individual branches in the repository, '
                    'use "bzr svn-import".')
        target_transport = get_transport(url, possible_transports)
        target_transport.ensure_base()
        require_colocated = ("branch"
                             in target_transport.get_segment_parameters())
        cloning_format = self.cloning_metadir(
            require_colocated=require_colocated)
        # Create/update the result branch
        result = cloning_format.initialize_on_transport(target_transport)

        source_repository = self.find_repository()
        if force_new_repo:
            result_repo = result.create_repository()
            target_is_empty = True
        else:
            try:
                result_repo = result.find_repository()
            except errors.NoRepositoryPresent:
                result_repo = result.create_repository()
                target_is_empty = True
            else:
                target_is_empty = None  # Unknown
        if stacked:
            raise UnstackableBranchFormat(self._format.get_branch_format(),
                                          self.root_transport.base)
        interrepo = InterRepository.get(source_repository, result_repo)
        try:
            source_branch = self.open_branch()
        except errors.NotBranchError:
            source_branch = None
            project = None
            mapping = None
        else:
            project = source_branch.project
            mapping = source_branch.mapping
        interrepo.fetch(revision_id=revision_id,
                        project=project,
                        mapping=mapping,
                        target_is_empty=target_is_empty,
                        exclude_non_mainline=False)
        if source_branch is not None:
            if revision_id is None:
                revision_id = source_branch.last_revision()
            result_branch = source_branch.sprout(result,
                                                 revision_id=revision_id,
                                                 repository=result_repo)
            interbranch = InterBranch.get(source_branch, result_branch)
            interbranch.fetch(stop_revision=revision_id,
                              exclude_non_mainline=False)  # For the tags
        else:
            result_branch = result.create_branch()
        if (create_tree_if_local
                and isinstance(target_transport, LocalTransport)
                and (result_repo is None or result_repo.make_working_trees())):
            result.create_workingtree(accelerator_tree=accelerator_tree,
                                      hardlink=hardlink,
                                      from_branch=result_branch)
        return result
Example #7
0
 def __init__(self, source, target, graph=None):
     InterRepository.__init__(self, source, target)
     self._graph = graph
     # Dictionary: revid -> branch_path -> (foreign_revid, mapping)
     self._foreign_info = defaultdict(dict)
Example #8
0
def default_test_list():
    """Generate the default list of interrepo permutations to test."""
    from breezy.bzr import (
        groupcompress_repo,
        knitrepo,
        knitpack_repo,
    )
    result = []

    def add_combo(interrepo_cls,
                  from_format,
                  to_format,
                  extra_setup=None,
                  label=None):
        if label is None:
            label = interrepo_cls.__name__
        result.append((label, from_format, to_format, extra_setup))

    # test the default InterRepository between format 6 and the current
    # default format.
    # XXX: robertc 20060220 reinstate this when there are two supported
    # formats which do not have an optimal code path between them.
    # result.append((InterRepository,
    #               RepositoryFormat6(),
    #               RepositoryFormatKnit1()))
    for optimiser_class in InterRepository.iter_optimisers():
        format_to_test = optimiser_class._get_repo_format_to_test()
        if format_to_test is not None:
            add_combo(optimiser_class, format_to_test, format_to_test)
    # if there are specific combinations we want to use, we can add them
    # here. We want to test rich root upgrading.
    # XXX: although we attach InterRepository class names to these scenarios,
    # there's nothing asserting that these labels correspond to what is
    # actually used.

    def force_known_graph(testcase):
        from breezy.bzr.fetch import Inter1and2Helper
        testcase.overrideAttr(Inter1and2Helper, 'known_graph_threshold', -1)

    # Gather extra scenarios from the repository implementations,
    # as InterRepositories can be used by Repository implementations
    # they aren't aware of.
    for module_name in format_registry._get_all_modules():
        module = pyutils.get_named_object(module_name)
        try:
            get_extra_interrepo_test_combinations = getattr(
                module, "get_extra_interrepo_test_combinations")
        except AttributeError:
            continue
        for (interrepo_cls, from_format,
             to_format) in (get_extra_interrepo_test_combinations()):
            add_combo(interrepo_cls, from_format, to_format)
    add_combo(InterRepository, knitrepo.RepositoryFormatKnit1(),
              knitrepo.RepositoryFormatKnit3())
    add_combo(knitrepo.InterKnitRepo, knitrepo.RepositoryFormatKnit1(),
              knitpack_repo.RepositoryFormatKnitPack1())
    add_combo(knitrepo.InterKnitRepo,
              knitpack_repo.RepositoryFormatKnitPack1(),
              knitrepo.RepositoryFormatKnit1())
    add_combo(knitrepo.InterKnitRepo, knitrepo.RepositoryFormatKnit3(),
              knitpack_repo.RepositoryFormatKnitPack3())
    add_combo(knitrepo.InterKnitRepo,
              knitpack_repo.RepositoryFormatKnitPack3(),
              knitrepo.RepositoryFormatKnit3())
    add_combo(knitrepo.InterKnitRepo,
              knitpack_repo.RepositoryFormatKnitPack3(),
              knitpack_repo.RepositoryFormatKnitPack4())
    add_combo(InterDifferingSerializer,
              knitpack_repo.RepositoryFormatKnitPack1(),
              knitpack_repo.RepositoryFormatKnitPack6RichRoot())
    add_combo(InterDifferingSerializer,
              knitpack_repo.RepositoryFormatKnitPack1(),
              knitpack_repo.RepositoryFormatKnitPack6RichRoot(),
              force_known_graph,
              label='InterDifferingSerializer+get_known_graph_ancestry')
    add_combo(InterDifferingSerializer,
              knitpack_repo.RepositoryFormatKnitPack6RichRoot(),
              groupcompress_repo.RepositoryFormat2a())
    add_combo(InterDifferingSerializer,
              groupcompress_repo.RepositoryFormat2a(),
              knitpack_repo.RepositoryFormatKnitPack6RichRoot())
    return result
Example #9
0
 def __init__(self, source, target):
     InterRepository.__init__(self, source, target)