~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2008-07-07 10:31:06 UTC
  • mfrom: (3221.11.29 reconfigure.shallow)
  • mto: This revision was merged to the branch mainline in revision 3537.
  • Revision ID: mbp@sourcefrog.net-20080707103106-jpch6tczx7x2yuq0
merge all stacking threads; some tests currently failing

Show diffs side-by-side

added added

removed removed

Lines of Context:
947
947
 
948
948
    def sprout(self, url, revision_id=None, force_new_repo=False,
949
949
               recurse='down', possible_transports=None,
950
 
               accelerator_tree=None, hardlink=False):
 
950
               accelerator_tree=None, hardlink=False, stacked=False):
951
951
        """Create a copy of this bzrdir prepared for use as a new line of
952
952
        development.
953
953
 
966
966
            content is different.
967
967
        :param hardlink: If true, hard-link files from accelerator_tree,
968
968
            where possible.
 
969
        :param stacked: If true, create a stacked branch referring to the
 
970
            location of this control directory.
969
971
        """
970
972
        target_transport = get_transport(url, possible_transports)
971
973
        target_transport.ensure_base()
974
976
        try:
975
977
            source_branch = self.open_branch()
976
978
            source_repository = source_branch.repository
 
979
            if stacked:
 
980
                stacked_branch_url = self.root_transport.base
 
981
            else:
 
982
                try:
 
983
                    stacked_branch_url = source_branch.get_stacked_on()
 
984
                except (errors.NotStacked, errors.UnstackableBranchFormat,
 
985
                    errors.UnstackableRepositoryFormat):
 
986
                    stacked_branch_url = None
977
987
        except errors.NotBranchError:
978
988
            source_branch = None
979
989
            try:
980
990
                source_repository = self.open_repository()
981
991
            except errors.NoRepositoryPresent:
982
992
                source_repository = None
 
993
            stacked_branch_url = None
983
994
        if force_new_repo:
984
995
            result_repo = None
985
996
        else:
987
998
                result_repo = result.find_repository()
988
999
            except errors.NoRepositoryPresent:
989
1000
                result_repo = None
990
 
        if source_repository is None and result_repo is not None:
991
 
            pass
992
 
        elif source_repository is None and result_repo is None:
993
 
            # no repo available, make a new one
994
 
            result.create_repository()
995
 
        elif source_repository is not None and result_repo is None:
 
1001
 
 
1002
        # Create/update the result repository as required
 
1003
        if source_repository is None:
 
1004
            if result_repo is None:
 
1005
                # no repo available, make a new one
 
1006
                result.create_repository()
 
1007
        elif stacked_branch_url is not None:
 
1008
            if result_repo is None:
 
1009
                result_repo = source_repository._format.initialize(result)
 
1010
            stacked_dir = BzrDir.open(stacked_branch_url)
 
1011
            try:
 
1012
                stacked_repo = stacked_dir.open_branch().repository
 
1013
            except errors.NotBranchError:
 
1014
                stacked_repo = stacked_dir.open_repository()
 
1015
            result_repo.add_fallback_repository(stacked_repo)
 
1016
            result_repo.fetch(source_repository, revision_id=revision_id)
 
1017
        elif result_repo is None:
996
1018
            # have source, and want to make a new target repo
997
1019
            result_repo = source_repository.sprout(result,
998
1020
                                                   revision_id=revision_id)
999
1021
        else:
1000
 
            # fetch needed content into target.
1001
 
            if source_repository is not None:
1002
 
                # would rather do 
1003
 
                # source_repository.copy_content_into(result_repo,
1004
 
                #                                     revision_id=revision_id)
1005
 
                # so we can override the copy method
1006
 
                result_repo.fetch(source_repository, revision_id=revision_id)
 
1022
            # Fetch needed content into target.
 
1023
            # Would rather do it this way ...
 
1024
            # source_repository.copy_content_into(result_repo,
 
1025
            #                                     revision_id=revision_id)
 
1026
            # so we can override the copy method
 
1027
            result_repo.fetch(source_repository, revision_id=revision_id)
 
1028
 
 
1029
        # Create/update the result branch
1007
1030
        if source_branch is not None:
1008
 
            source_branch.sprout(result, revision_id=revision_id)
 
1031
            result_branch = source_branch.sprout(result,
 
1032
                revision_id=revision_id)
1009
1033
        else:
1010
 
            result.create_branch()
 
1034
            result_branch = result.create_branch()
 
1035
        if stacked_branch_url is not None:
 
1036
            result_branch.set_stacked_on(stacked_branch_url)
 
1037
 
 
1038
        # Create/update the result working tree
1011
1039
        if isinstance(target_transport, LocalTransport) and (
1012
1040
            result_repo is None or result_repo.make_working_trees()):
1013
1041
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1028
1056
                basis = wt.basis_tree()
1029
1057
                basis.lock_read()
1030
1058
                subtrees = basis.iter_references()
1031
 
                recurse_branch = wt.branch
1032
1059
            elif source_branch is not None:
1033
1060
                basis = source_branch.basis_tree()
1034
1061
                basis.lock_read()
1035
1062
                subtrees = basis.iter_references()
1036
 
                recurse_branch = source_branch
1037
1063
            else:
1038
1064
                subtrees = []
1039
1065
                basis = None
1043
1069
                    sublocation = source_branch.reference_parent(file_id, path)
1044
1070
                    sublocation.bzrdir.sprout(target,
1045
1071
                        basis.get_reference_revision(file_id, path),
1046
 
                        force_new_repo=force_new_repo, recurse=recurse)
 
1072
                        force_new_repo=force_new_repo, recurse=recurse,
 
1073
                        stacked=stacked)
1047
1074
            finally:
1048
1075
                if basis is not None:
1049
1076
                    basis.unlock()
1183
1210
 
1184
1211
    def sprout(self, url, revision_id=None, force_new_repo=False,
1185
1212
               possible_transports=None, accelerator_tree=None,
1186
 
               hardlink=False):
 
1213
               hardlink=False, stacked=False):
1187
1214
        """See BzrDir.sprout()."""
 
1215
        if stacked:
 
1216
            raise errors.UnstackableBranchFormat(
 
1217
                self._format, self.root_transport.base)
1188
1218
        from bzrlib.workingtree import WorkingTreeFormat2
1189
1219
        self._make_tail(url)
1190
1220
        result = self._format._initialize_for_clone(url)
2407
2437
            pass
2408
2438
        else:
2409
2439
            # TODO: conversions of Branch and Tree should be done by
2410
 
            # InterXFormat lookups
 
2440
            # InterXFormat lookups/some sort of registry.
2411
2441
            # Avoid circular imports
2412
2442
            from bzrlib import branch as _mod_branch
2413
 
            if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2414
 
                self.target_format.get_branch_format().__class__ is
2415
 
                _mod_branch.BzrBranchFormat6):
2416
 
                branch_converter = _mod_branch.Converter5to6()
 
2443
            old = branch._format.__class__
 
2444
            new = self.target_format.get_branch_format().__class__
 
2445
            while old != new:
 
2446
                if (old == _mod_branch.BzrBranchFormat5 and
 
2447
                    new in (_mod_branch.BzrBranchFormat6,
 
2448
                        _mod_branch.BzrBranchFormat7)):
 
2449
                    branch_converter = _mod_branch.Converter5to6()
 
2450
                elif (old == _mod_branch.BzrBranchFormat6 and
 
2451
                    new == _mod_branch.BzrBranchFormat7):
 
2452
                    branch_converter = _mod_branch.Converter6to7()
 
2453
                else:
 
2454
                    raise errors.BadConversionTarget("No converter", new)
2417
2455
                branch_converter.convert(branch)
 
2456
                branch = self.bzrdir.open_branch()
 
2457
                old = branch._format.__class__
2418
2458
        try:
2419
2459
            tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2420
2460
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2806
2846
    )
2807
2847
# The following two formats should always just be aliases.
2808
2848
format_registry.register_metadir('development',
2809
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
 
2849
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
2810
2850
    help='Current development format. Can convert data to and from pack-0.92 '
2811
2851
        '(and anything compatible with pack-0.92) format repositories. '
2812
 
        'Repositories in this format can only be read by bzr.dev. '
 
2852
        'Repositories and branches in this format can only be read by bzr.dev. '
2813
2853
        'Please read '
2814
2854
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2815
2855
        'before use.',
2816
 
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2856
    branch_format='bzrlib.branch.BzrBranchFormat7',
2817
2857
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2818
2858
    experimental=True,
2819
2859
    alias=True,
2820
2860
    )
2821
2861
format_registry.register_metadir('development-subtree',
2822
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
 
2862
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
2823
2863
    help='Current development format, subtree variant. Can convert data to and '
2824
 
        'from pack-0.92 (and anything compatible with pack-0.92) format '
2825
 
        'repositories. Repositories in this format can only be read by '
2826
 
        'bzr.dev. Please read '
 
2864
        'from pack-0.92-subtree (and anything compatible with '
 
2865
        'pack-0.92-subtree) format repositories. Repositories and branches in '
 
2866
        'this format can only be read by bzr.dev. Please read '
2827
2867
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2828
2868
        'before use.',
2829
 
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2869
    branch_format='bzrlib.branch.BzrBranchFormat7',
2830
2870
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2831
2871
    experimental=True,
2832
2872
    alias=True,
2854
2894
    hidden=True,
2855
2895
    experimental=True,
2856
2896
    )
 
2897
format_registry.register_metadir('development1',
 
2898
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
 
2899
    help='A branch and pack based repository that supports stacking. '
 
2900
        'Please read '
 
2901
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
2902
        'before use.',
 
2903
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2904
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2905
    hidden=True,
 
2906
    experimental=True,
 
2907
    )
 
2908
format_registry.register_metadir('development1-subtree',
 
2909
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
 
2910
    help='A branch and pack based repository that supports stacking. '
 
2911
        'Please read '
 
2912
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
2913
        'before use.',
 
2914
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2915
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2916
    hidden=True,
 
2917
    experimental=True,
 
2918
    )
 
2919
# The current format that is made on 'bzr init'.
2857
2920
format_registry.set_default('pack-0.92')