~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2008-07-25 05:32:45 UTC
  • mto: This revision was merged to the branch mainline in revision 3579.
  • Revision ID: mbp@sourcefrog.net-20080725053245-pzj4ojq610mls3rv
branch --stacked should force a stacked format

Show diffs side-by-side

added added

removed removed

Lines of Context:
380
380
        repository used instead.
381
381
 
382
382
        If stack_on is supplied, will not seek a containing shared repo.
 
383
 
383
384
        :param force_new_repo: If True, require a new repository to be created.
384
385
        :param stack_on: If supplied, the location to stack on.  If not
385
386
            supplied, a default_stack_on location may be used.
978
979
            return False
979
980
 
980
981
    def _cloning_metadir(self):
981
 
        """Produce a metadir suitable for cloning with."""
 
982
        """Produce a metadir suitable for cloning with.
 
983
        
 
984
        :returns: (destination_bzrdir_format, source_repository)
 
985
        """
982
986
        result_format = self._format.__class__()
983
987
        try:
984
988
            try:
1013
1017
        These operations may produce workingtrees (yes, even though they're
1014
1018
        "cloning" something that doesn't have a tree), so a viable workingtree
1015
1019
        format must be selected.
 
1020
 
 
1021
        :returns: a BzrDirFormat with all component formats either set
 
1022
            appropriately or set to None if that component should not be 
 
1023
            created.
1016
1024
        """
1017
1025
        format, repository = self._cloning_metadir()
1018
1026
        if format._workingtree_format is None:
1073
1081
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1074
1082
        result_repo = repository_policy.acquire_repository()
1075
1083
        if source_repository is not None:
 
1084
            # XXX: Isn't this redundant with the copy_content_into used below
 
1085
            # after creating the branch? -- mbp 20080724
1076
1086
            result_repo.fetch(source_repository, revision_id=revision_id)
1077
1087
 
1078
1088
        # Create/update the result branch
1079
 
        if source_branch is not None:
1080
 
            result_branch = source_branch.sprout(result,
1081
 
                revision_id=revision_id)
1082
 
        else:
 
1089
        if ((stacked 
 
1090
             or repository_policy._require_stacking 
 
1091
             or repository_policy._stack_on)
 
1092
            and not result._format.get_branch_format().supports_stacking()):
 
1093
            # force a branch that can support stacking 
 
1094
            from bzrlib.branch import BzrBranchFormat7
 
1095
            format = BzrBranchFormat7()
 
1096
            result_branch = format.initialize(result)
 
1097
            mutter("using %r for stacking" % (format,))
 
1098
        elif source_branch is None:
 
1099
            # this is for sprouting a bzrdir without a branch; is that
 
1100
            # actually useful?
1083
1101
            result_branch = result.create_branch()
 
1102
        else:
 
1103
            result_branch = source_branch._format.initialize(result)
 
1104
        mutter("created new branch %r" % (result_branch,))
1084
1105
        repository_policy.configure_branch(result_branch)
 
1106
        if source_branch is not None:
 
1107
            # XXX: this duplicates Branch.sprout(); it probably belongs on an
 
1108
            # InterBranch method? -- mbp 20080724
 
1109
            source_branch.copy_content_into(result_branch,
 
1110
                 revision_id=revision_id)
 
1111
            result_branch.set_parent(self.root_transport.base)
1085
1112
 
1086
1113
        # Create/update the result working tree
1087
1114
        if isinstance(target_transport, LocalTransport) and (
2859
2886
 
2860
2887
        Creates the desired repository in the bzrdir we already have.
2861
2888
        """
2862
 
        repository = self._bzrdir.create_repository(shared=shared)
 
2889
        if self._stack_on or self._require_stacking:
 
2890
            # we may be coming from a format that doesn't support stacking,
 
2891
            # but we require it in the destination, so force creation of a new
 
2892
            # one here.
 
2893
            #
 
2894
            # TODO: perhaps this should be treated as a distinct repository
 
2895
            # acquisition policy?
 
2896
            repository_format = self._bzrdir._format.repository_format
 
2897
            if not repository_format.supports_external_lookups:
 
2898
                # should possibly be controlled by the registry rather than
 
2899
                # hardcoded here.
 
2900
                from bzrlib.repofmt import pack_repo
 
2901
                if repository_format.rich_root_data:
 
2902
                    repository_format = \
 
2903
                        pack_repo.RepositoryFormatKnitPack5RichRoot()
 
2904
                else:
 
2905
                    repository_format = pack_repo.RepositoryFormatKnitPack5()
 
2906
                note("using %r for stacking" % (repository_format,))
 
2907
            repository = repository_format.initialize(self._bzrdir,
 
2908
                shared=shared)
 
2909
        else:
 
2910
            # let bzrdir choose
 
2911
            repository = self._bzrdir.create_repository(shared=shared)
2863
2912
        self._add_fallback(repository)
2864
2913
        if make_working_trees is not None:
2865
2914
            repository.set_make_working_trees(make_working_trees)