~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-09 13:58:59 UTC
  • mfrom: (3533.2.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080709135859-wq3r1d1fjcafelgw
(jam) (bug #243536) tsort.merge_sorted() can ignore ghosts in the
        mainline history passed in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
973
973
 
974
974
    def sprout(self, url, revision_id=None, force_new_repo=False,
975
975
               recurse='down', possible_transports=None,
976
 
               accelerator_tree=None, hardlink=False, stacked=False):
 
976
               accelerator_tree=None, hardlink=False):
977
977
        """Create a copy of this bzrdir prepared for use as a new line of
978
978
        development.
979
979
 
992
992
            content is different.
993
993
        :param hardlink: If true, hard-link files from accelerator_tree,
994
994
            where possible.
995
 
        :param stacked: If true, create a stacked branch referring to the
996
 
            location of this control directory.
997
995
        """
998
996
        target_transport = get_transport(url, possible_transports)
999
997
        target_transport.ensure_base()
1002
1000
        try:
1003
1001
            source_branch = self.open_branch()
1004
1002
            source_repository = source_branch.repository
1005
 
            if stacked:
1006
 
                stacked_branch_url = self.root_transport.base
1007
 
            else:
1008
 
                try:
1009
 
                    stacked_branch_url = source_branch.get_stacked_on()
1010
 
                except (errors.NotStacked, errors.UnstackableBranchFormat,
1011
 
                    errors.UnstackableRepositoryFormat):
1012
 
                    stacked_branch_url = None
1013
1003
        except errors.NotBranchError:
1014
1004
            source_branch = None
1015
1005
            try:
1016
1006
                source_repository = self.open_repository()
1017
1007
            except errors.NoRepositoryPresent:
1018
1008
                source_repository = None
1019
 
            stacked_branch_url = None
1020
1009
        if force_new_repo:
1021
1010
            result_repo = None
1022
1011
        else:
1024
1013
                result_repo = result.find_repository()
1025
1014
            except errors.NoRepositoryPresent:
1026
1015
                result_repo = None
1027
 
 
1028
 
        # Create/update the result repository as required
1029
 
        if source_repository is None:
1030
 
            if result_repo is None:
1031
 
                # no repo available, make a new one
1032
 
                result.create_repository()
1033
 
        elif stacked_branch_url is not None:
1034
 
            if result_repo is None:
1035
 
                result_repo = source_repository._format.initialize(result)
1036
 
            stacked_dir = BzrDir.open(stacked_branch_url)
1037
 
            try:
1038
 
                stacked_repo = stacked_dir.open_branch().repository
1039
 
            except errors.NotBranchError:
1040
 
                stacked_repo = stacked_dir.open_repository()
1041
 
            result_repo.add_fallback_repository(stacked_repo)
1042
 
            result_repo.fetch(source_repository, revision_id=revision_id)
1043
 
        elif result_repo is None:
 
1016
        if source_repository is None and result_repo is not None:
 
1017
            pass
 
1018
        elif source_repository is None and result_repo is None:
 
1019
            # no repo available, make a new one
 
1020
            result.create_repository()
 
1021
        elif source_repository is not None and result_repo is None:
1044
1022
            # have source, and want to make a new target repo
1045
1023
            result_repo = source_repository.sprout(result,
1046
1024
                                                   revision_id=revision_id)
1047
1025
        else:
1048
 
            # Fetch needed content into target.
1049
 
            # Would rather do it this way ...
1050
 
            # source_repository.copy_content_into(result_repo,
1051
 
            #                                     revision_id=revision_id)
1052
 
            # so we can override the copy method
1053
 
            result_repo.fetch(source_repository, revision_id=revision_id)
1054
 
 
1055
 
        # Create/update the result branch
 
1026
            # fetch needed content into target.
 
1027
            if source_repository is not None:
 
1028
                # would rather do 
 
1029
                # source_repository.copy_content_into(result_repo,
 
1030
                #                                     revision_id=revision_id)
 
1031
                # so we can override the copy method
 
1032
                result_repo.fetch(source_repository, revision_id=revision_id)
1056
1033
        if source_branch is not None:
1057
 
            result_branch = source_branch.sprout(result,
1058
 
                revision_id=revision_id)
 
1034
            source_branch.sprout(result, revision_id=revision_id)
1059
1035
        else:
1060
 
            result_branch = result.create_branch()
1061
 
        if stacked_branch_url is not None:
1062
 
            result_branch.set_stacked_on(stacked_branch_url)
1063
 
 
1064
 
        # Create/update the result working tree
 
1036
            result.create_branch()
1065
1037
        if isinstance(target_transport, LocalTransport) and (
1066
1038
            result_repo is None or result_repo.make_working_trees()):
1067
1039
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1082
1054
                basis = wt.basis_tree()
1083
1055
                basis.lock_read()
1084
1056
                subtrees = basis.iter_references()
 
1057
                recurse_branch = wt.branch
1085
1058
            elif source_branch is not None:
1086
1059
                basis = source_branch.basis_tree()
1087
1060
                basis.lock_read()
1088
1061
                subtrees = basis.iter_references()
 
1062
                recurse_branch = source_branch
1089
1063
            else:
1090
1064
                subtrees = []
1091
1065
                basis = None
1095
1069
                    sublocation = source_branch.reference_parent(file_id, path)
1096
1070
                    sublocation.bzrdir.sprout(target,
1097
1071
                        basis.get_reference_revision(file_id, path),
1098
 
                        force_new_repo=force_new_repo, recurse=recurse,
1099
 
                        stacked=stacked)
 
1072
                        force_new_repo=force_new_repo, recurse=recurse)
1100
1073
            finally:
1101
1074
                if basis is not None:
1102
1075
                    basis.unlock()
1236
1209
 
1237
1210
    def sprout(self, url, revision_id=None, force_new_repo=False,
1238
1211
               possible_transports=None, accelerator_tree=None,
1239
 
               hardlink=False, stacked=False):
 
1212
               hardlink=False):
1240
1213
        """See BzrDir.sprout()."""
1241
 
        if stacked:
1242
 
            raise errors.UnstackableBranchFormat(
1243
 
                self._format, self.root_transport.base)
1244
1214
        from bzrlib.workingtree import WorkingTreeFormat2
1245
1215
        self._make_tail(url)
1246
1216
        result = self._format._initialize_for_clone(url)
2463
2433
            pass
2464
2434
        else:
2465
2435
            # TODO: conversions of Branch and Tree should be done by
2466
 
            # InterXFormat lookups/some sort of registry.
 
2436
            # InterXFormat lookups
2467
2437
            # Avoid circular imports
2468
2438
            from bzrlib import branch as _mod_branch
2469
 
            old = branch._format.__class__
2470
 
            new = self.target_format.get_branch_format().__class__
2471
 
            while old != new:
2472
 
                if (old == _mod_branch.BzrBranchFormat5 and
2473
 
                    new in (_mod_branch.BzrBranchFormat6,
2474
 
                        _mod_branch.BzrBranchFormat7)):
2475
 
                    branch_converter = _mod_branch.Converter5to6()
2476
 
                elif (old == _mod_branch.BzrBranchFormat6 and
2477
 
                    new == _mod_branch.BzrBranchFormat7):
2478
 
                    branch_converter = _mod_branch.Converter6to7()
2479
 
                else:
2480
 
                    raise errors.BadConversionTarget("No converter", new)
 
2439
            if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
 
2440
                self.target_format.get_branch_format().__class__ is
 
2441
                _mod_branch.BzrBranchFormat6):
 
2442
                branch_converter = _mod_branch.Converter5to6()
2481
2443
                branch_converter.convert(branch)
2482
 
                branch = self.bzrdir.open_branch()
2483
 
                old = branch._format.__class__
2484
2444
        try:
2485
2445
            tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2486
2446
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2872
2832
    )
2873
2833
# The following two formats should always just be aliases.
2874
2834
format_registry.register_metadir('development',
2875
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
 
2835
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
2876
2836
    help='Current development format. Can convert data to and from pack-0.92 '
2877
2837
        '(and anything compatible with pack-0.92) format repositories. '
2878
 
        'Repositories and branches in this format can only be read by bzr.dev. '
 
2838
        'Repositories in this format can only be read by bzr.dev. '
2879
2839
        'Please read '
2880
2840
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2881
2841
        'before use.',
2882
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2842
    branch_format='bzrlib.branch.BzrBranchFormat6',
2883
2843
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2884
2844
    experimental=True,
2885
2845
    alias=True,
2886
2846
    )
2887
2847
format_registry.register_metadir('development-subtree',
2888
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
 
2848
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
2889
2849
    help='Current development format, subtree variant. Can convert data to and '
2890
 
        'from pack-0.92-subtree (and anything compatible with '
2891
 
        'pack-0.92-subtree) format repositories. Repositories and branches in '
2892
 
        'this format can only be read by bzr.dev. Please read '
 
2850
        'from pack-0.92 (and anything compatible with pack-0.92) format '
 
2851
        'repositories. Repositories in this format can only be read by '
 
2852
        'bzr.dev. Please read '
2893
2853
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2894
2854
        'before use.',
2895
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2855
    branch_format='bzrlib.branch.BzrBranchFormat6',
2896
2856
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2897
2857
    experimental=True,
2898
2858
    alias=True,
2920
2880
    hidden=True,
2921
2881
    experimental=True,
2922
2882
    )
2923
 
format_registry.register_metadir('development1',
2924
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
2925
 
    help='A branch and pack based repository that supports stacking. '
2926
 
        'Please read '
2927
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2928
 
        'before use.',
2929
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
2930
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2931
 
    hidden=True,
2932
 
    experimental=True,
2933
 
    )
2934
 
format_registry.register_metadir('development1-subtree',
2935
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
2936
 
    help='A branch and pack based repository that supports stacking. '
2937
 
        'Please read '
2938
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2939
 
        'before use.',
2940
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
2941
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2942
 
    hidden=True,
2943
 
    experimental=True,
2944
 
    )
2945
 
# The current format that is made on 'bzr init'.
2946
2883
format_registry.set_default('pack-0.92')