~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Andrew Bennetts
  • Date: 2008-08-07 00:25:38 UTC
  • mfrom: (3612 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3613.
  • Revision ID: andrew.bennetts@canonical.com-20080807002538-mtl1fcgy2fdabha4
Merge from bzr.dev.

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
        format_forced = False
 
1090
        if ((stacked 
 
1091
             or repository_policy._require_stacking 
 
1092
             or repository_policy._stack_on)
 
1093
            and not result._format.get_branch_format().supports_stacking()):
 
1094
            # We need to make a stacked branch, but the default format for the
 
1095
            # target doesn't support stacking.  So force a branch that *can*
 
1096
            # support stacking. 
 
1097
            from bzrlib.branch import BzrBranchFormat7
 
1098
            format = BzrBranchFormat7()
 
1099
            result_branch = format.initialize(result)
 
1100
            mutter("using %r for stacking" % (format,))
 
1101
            format_forced = True
 
1102
        elif source_branch is None:
 
1103
            # this is for sprouting a bzrdir without a branch; is that
 
1104
            # actually useful?
1083
1105
            result_branch = result.create_branch()
 
1106
        else:
 
1107
            result_branch = source_branch.sprout(
 
1108
                result, revision_id=revision_id)
 
1109
        mutter("created new branch %r" % (result_branch,))
1084
1110
        repository_policy.configure_branch(result_branch)
 
1111
        if source_branch is not None and format_forced:
 
1112
            # XXX: this duplicates Branch.sprout(); it probably belongs on an
 
1113
            # InterBranch method? -- mbp 20080724
 
1114
            source_branch.copy_content_into(result_branch,
 
1115
                 revision_id=revision_id)
 
1116
            result_branch.set_parent(self.root_transport.base)
1085
1117
 
1086
1118
        # Create/update the result working tree
1087
1119
        if isinstance(target_transport, LocalTransport) and (
2859
2891
 
2860
2892
        Creates the desired repository in the bzrdir we already have.
2861
2893
        """
2862
 
        repository = self._bzrdir.create_repository(shared=shared)
 
2894
        if self._stack_on or self._require_stacking:
 
2895
            # we may be coming from a format that doesn't support stacking,
 
2896
            # but we require it in the destination, so force creation of a new
 
2897
            # one here.
 
2898
            #
 
2899
            # TODO: perhaps this should be treated as a distinct repository
 
2900
            # acquisition policy?
 
2901
            repository_format = self._bzrdir._format.repository_format
 
2902
            if not repository_format.supports_external_lookups:
 
2903
                # should possibly be controlled by the registry rather than
 
2904
                # hardcoded here.
 
2905
                from bzrlib.repofmt import pack_repo
 
2906
                if repository_format.rich_root_data:
 
2907
                    repository_format = \
 
2908
                        pack_repo.RepositoryFormatKnitPack5RichRoot()
 
2909
                else:
 
2910
                    repository_format = pack_repo.RepositoryFormatKnitPack5()
 
2911
                note("using %r for stacking" % (repository_format,))
 
2912
            repository = repository_format.initialize(self._bzrdir,
 
2913
                shared=shared)
 
2914
        else:
 
2915
            # let bzrdir choose
 
2916
            repository = self._bzrdir.create_repository(shared=shared)
2863
2917
        self._add_fallback(repository)
2864
2918
        if make_working_trees is not None:
2865
2919
            repository.set_make_working_trees(make_working_trees)