~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Mark Hammond
  • Date: 2008-12-28 05:21:23 UTC
  • mfrom: (3920 +trunk)
  • mto: (3932.1.1 prepare-1.11)
  • mto: This revision was merged to the branch mainline in revision 3937.
  • Revision ID: mhammond@skippinet.com.au-20081228052123-f78xs5sbdkotshwf
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
218
218
            make_working_trees = local_repo.make_working_trees()
219
219
            result_repo = repository_policy.acquire_repository(
220
220
                make_working_trees, local_repo.is_shared())
 
221
            if not require_stacking and repository_policy._require_stacking:
 
222
                require_stacking = True
 
223
                result._format.require_stacking()
221
224
            result_repo.fetch(local_repo, revision_id=revision_id)
222
225
        else:
223
226
            result_repo = None
516
519
        """
517
520
        raise NotImplementedError(self.create_workingtree)
518
521
 
 
522
    def backup_bzrdir(self):
 
523
        """Backup this bzr control directory.
 
524
        
 
525
        :return: Tuple with old path name and new path name
 
526
        """
 
527
        self.root_transport.copy_tree('.bzr', 'backup.bzr')
 
528
        return (self.root_transport.abspath('.bzr'),
 
529
                self.root_transport.abspath('backup.bzr'))
 
530
 
519
531
    def retire_bzrdir(self, limit=10000):
520
532
        """Permanently disable the bzrdir.
521
533
 
773
785
        :param transport: Transport containing the bzrdir.
774
786
        :param _unsupported: private.
775
787
        """
 
788
        # Keep initial base since 'transport' may be modified while following
 
789
        # the redirections.
776
790
        base = transport.base
777
 
 
778
791
        def find_format(transport):
779
792
            return transport, BzrDirFormat.find_format(
780
793
                transport, _server_formats=_server_formats)
781
794
 
782
795
        def redirected(transport, e, redirection_notice):
783
 
            qualified_source = e.get_source_url()
784
 
            relpath = transport.relpath(qualified_source)
785
 
            if not e.target.endswith(relpath):
786
 
                # Not redirected to a branch-format, not a branch
787
 
                raise errors.NotBranchError(path=e.target)
788
 
            target = e.target[:-len(relpath)]
 
796
            redirected_transport = transport._redirected_to(e.source, e.target)
 
797
            if redirected_transport is None:
 
798
                raise errors.NotBranchError(base)
789
799
            note('%s is%s redirected to %s',
790
 
                 transport.base, e.permanently, target)
791
 
            # Let's try with a new transport
792
 
            # FIXME: If 'transport' has a qualifier, this should
793
 
            # be applied again to the new transport *iff* the
794
 
            # schemes used are the same. Uncomment this code
795
 
            # once the function (and tests) exist.
796
 
            # -- vila20070212
797
 
            #target = urlutils.copy_url_qualifiers(original, target)
798
 
            return get_transport(target)
 
800
                 transport.base, e.permanently, redirected_transport.base)
 
801
            return redirected_transport
799
802
 
800
803
        try:
801
804
            transport, format = do_catching_redirections(find_format,
1035
1038
                return format
1036
1039
            tree_format = repository._format._matchingbzrdir.workingtree_format
1037
1040
            format.workingtree_format = tree_format.__class__()
1038
 
        if (require_stacking and not
1039
 
            format.get_branch_format().supports_stacking()):
1040
 
            # We need to make a stacked branch, but the default format for the
1041
 
            # target doesn't support stacking.  So force a branch that *can*
1042
 
            # support stacking.
1043
 
            from bzrlib.branch import BzrBranchFormat7
1044
 
            format._branch_format = BzrBranchFormat7()
1045
 
            mutter("using %r for stacking" % (format._branch_format,))
1046
 
            from bzrlib.repofmt import pack_repo
1047
 
            if format.repository_format.rich_root_data:
1048
 
                bzrdir_format_name = '1.6.1-rich-root'
1049
 
                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
1050
 
            else:
1051
 
                bzrdir_format_name = '1.6'
1052
 
                repo_format = pack_repo.RepositoryFormatKnitPack5()
1053
 
            note('Source format does not support stacking, using format:'
1054
 
                 ' \'%s\'\n  %s\n',
1055
 
                 bzrdir_format_name, repo_format.get_format_description())
1056
 
            format.repository_format = repo_format
 
1041
        if require_stacking:
 
1042
            format.require_stacking()
1057
1043
        return format
1058
1044
 
1059
1045
    def checkout_metadir(self):
2026
2012
    def set_branch_format(self, format):
2027
2013
        self._branch_format = format
2028
2014
 
 
2015
    def require_stacking(self):
 
2016
        if not self.get_branch_format().supports_stacking():
 
2017
            # We need to make a stacked branch, but the default format for the
 
2018
            # target doesn't support stacking.  So force a branch that *can*
 
2019
            # support stacking.
 
2020
            from bzrlib.branch import BzrBranchFormat7
 
2021
            self._branch_format = BzrBranchFormat7()
 
2022
            mutter("using %r for stacking" % (self._branch_format,))
 
2023
            from bzrlib.repofmt import pack_repo
 
2024
            if self.repository_format.rich_root_data:
 
2025
                bzrdir_format_name = '1.6.1-rich-root'
 
2026
                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
2027
            else:
 
2028
                bzrdir_format_name = '1.6'
 
2029
                repo_format = pack_repo.RepositoryFormatKnitPack5()
 
2030
            note('Source format does not support stacking, using format:'
 
2031
                 ' \'%s\'\n  %s\n',
 
2032
                 bzrdir_format_name, repo_format.get_format_description())
 
2033
            self.repository_format = repo_format
 
2034
 
2029
2035
    def get_converter(self, format=None):
2030
2036
        """See BzrDirFormat.get_converter()."""
2031
2037
        if format is None:
2586
2592
            # TODO: conversions of Branch and Tree should be done by
2587
2593
            # InterXFormat lookups
2588
2594
            if (isinstance(tree, workingtree.WorkingTree3) and
2589
 
                not isinstance(tree, workingtree_4.WorkingTree4) and
 
2595
                not isinstance(tree, workingtree_4.DirStateWorkingTree) and
2590
2596
                isinstance(self.target_format.workingtree_format,
2591
 
                    workingtree_4.WorkingTreeFormat4)):
 
2597
                    workingtree_4.DirStateWorkingTreeFormat)):
2592
2598
                workingtree_4.Converter3to4().convert(tree)
 
2599
            if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
 
2600
                not isinstance(tree, workingtree_4.WorkingTree5) and
 
2601
                isinstance(self.target_format.workingtree_format,
 
2602
                    workingtree_4.WorkingTreeFormat5)):
 
2603
                workingtree_4.Converter4to5().convert(tree)
2593
2604
        return to_convert
2594
2605
 
2595
2606
 
2650
2661
            return False
2651
2662
        return self.get_format_description() == other.get_format_description()
2652
2663
 
 
2664
    @property
 
2665
    def repository_format(self):
 
2666
        # Using a property to avoid early loading of remote
 
2667
        return remote.RemoteRepositoryFormat()
 
2668
 
2653
2669
 
2654
2670
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2655
2671
 
2673
2689
    def __init__(self):
2674
2690
        """Create a BzrDirFormatRegistry."""
2675
2691
        self._aliases = set()
 
2692
        self._registration_order = list()
2676
2693
        super(BzrDirFormatRegistry, self).__init__()
2677
2694
 
2678
2695
    def aliases(self):
2740
2757
            BzrDirFormatInfo(native, deprecated, hidden, experimental))
2741
2758
        if alias:
2742
2759
            self._aliases.add(key)
 
2760
        self._registration_order.append(key)
2743
2761
 
2744
2762
    def register_lazy(self, key, module_name, member_name, help, native=True,
2745
2763
        deprecated=False, hidden=False, experimental=False, alias=False):
2747
2765
            help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
2748
2766
        if alias:
2749
2767
            self._aliases.add(key)
 
2768
        self._registration_order.append(key)
2750
2769
 
2751
2770
    def set_default(self, key):
2752
2771
        """Set the 'default' key to be a clone of the supplied key.
2772
2791
        return self.get(key)()
2773
2792
 
2774
2793
    def help_topic(self, topic):
2775
 
        output = textwrap.dedent("""\
2776
 
            These formats can be used for creating branches, working trees, and
2777
 
            repositories.
2778
 
 
2779
 
            """)
 
2794
        output = ""
2780
2795
        default_realkey = None
2781
2796
        default_help = self.get_help('default')
2782
2797
        help_pairs = []
2783
 
        for key in self.keys():
 
2798
        for key in self._registration_order:
2784
2799
            if key == 'default':
2785
2800
                continue
2786
2801
            help = self.get_help(key)
2810
2825
                experimental_pairs.append((key, help))
2811
2826
            else:
2812
2827
                output += wrapped(key, help, info)
 
2828
        output += "\nSee ``bzr help formats`` for more about storage formats."
 
2829
        other_output = ""
2813
2830
        if len(experimental_pairs) > 0:
2814
 
            output += "Experimental formats are shown below.\n\n"
 
2831
            other_output += "Experimental formats are shown below.\n\n"
2815
2832
            for key, help in experimental_pairs:
2816
2833
                info = self.get_info(key)
2817
 
                output += wrapped(key, help, info)
 
2834
                other_output += wrapped(key, help, info)
 
2835
        else:
 
2836
            other_output += \
 
2837
                "No experimental formats are available.\n\n"
2818
2838
        if len(deprecated_pairs) > 0:
2819
 
            output += "Deprecated formats are shown below.\n\n"
 
2839
            other_output += "\nDeprecated formats are shown below.\n\n"
2820
2840
            for key, help in deprecated_pairs:
2821
2841
                info = self.get_info(key)
2822
 
                output += wrapped(key, help, info)
 
2842
                other_output += wrapped(key, help, info)
 
2843
        else:
 
2844
            other_output += \
 
2845
                "\nNo deprecated formats are available.\n\n"
 
2846
        other_output += \
 
2847
            "\nSee ``bzr help formats`` for more about storage formats."
2823
2848
 
2824
 
        return output
 
2849
        if topic == 'other-formats':
 
2850
            return other_output
 
2851
        else:
 
2852
            return output
2825
2853
 
2826
2854
 
2827
2855
class RepositoryAcquisitionPolicy(object):
2889
2917
        except errors.UnstackableRepositoryFormat:
2890
2918
            if self._require_stacking:
2891
2919
                raise
 
2920
        else:
 
2921
            self._require_stacking = True
2892
2922
 
2893
2923
    def acquire_repository(self, make_working_trees=None, shared=False):
2894
2924
        """Acquire a repository for this bzrdir.
2956
2986
        return self._repository
2957
2987
 
2958
2988
 
 
2989
# Please register new formats after old formats so that formats
 
2990
# appear in chronological order and format descriptions can build
 
2991
# on previous ones.
2959
2992
format_registry = BzrDirFormatRegistry()
2960
2993
format_registry.register('weave', BzrDirFormat6,
2961
2994
    'Pre-0.8 format.  Slower than knit and does not'
2962
2995
    ' support checkouts or shared repositories.',
2963
2996
    deprecated=True)
2964
 
format_registry.register_metadir('knit',
2965
 
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2966
 
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
2967
 
    branch_format='bzrlib.branch.BzrBranchFormat5',
2968
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2969
2997
format_registry.register_metadir('metaweave',
2970
2998
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2971
2999
    'Transitional format in 0.8.  Slower than knit.',
2972
3000
    branch_format='bzrlib.branch.BzrBranchFormat5',
2973
3001
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2974
3002
    deprecated=True)
 
3003
format_registry.register_metadir('knit',
 
3004
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
3005
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
 
3006
    branch_format='bzrlib.branch.BzrBranchFormat5',
 
3007
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
 
3008
    deprecated=True)
2975
3009
format_registry.register_metadir('dirstate',
2976
3010
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2977
3011
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2980
3014
    # this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
2981
3015
    # directly from workingtree_4 triggers a circular import.
2982
3016
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2983
 
    )
 
3017
    deprecated=True)
2984
3018
format_registry.register_metadir('dirstate-tags',
2985
3019
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2986
3020
    help='New in 0.15: Fast local operations and improved scaling for '
2988
3022
        ' Incompatible with bzr < 0.15.',
2989
3023
    branch_format='bzrlib.branch.BzrBranchFormat6',
2990
3024
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2991
 
    )
 
3025
    deprecated=True)
2992
3026
format_registry.register_metadir('rich-root',
2993
3027
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2994
3028
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
2995
 
        ' bzr < 1.0',
 
3029
        ' bzr < 1.0.',
2996
3030
    branch_format='bzrlib.branch.BzrBranchFormat6',
2997
3031
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2998
 
    )
 
3032
    deprecated=True)
2999
3033
format_registry.register_metadir('dirstate-with-subtree',
3000
3034
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
3001
3035
    help='New in 0.15: Fast local operations and improved scaling for '
3032
3066
    )
3033
3067
format_registry.register_metadir('rich-root-pack',
3034
3068
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3035
 
    help='New in 1.0: Pack-based format with data compatible with '
3036
 
        'rich-root format repositories. Incompatible with'
3037
 
        ' bzr < 1.0',
 
3069
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
 
3070
         '(needed for bzr-svn).',
3038
3071
    branch_format='bzrlib.branch.BzrBranchFormat6',
3039
3072
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3040
3073
    )
3041
3074
format_registry.register_metadir('1.6',
3042
3075
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3043
 
    help='A branch and pack based repository that supports stacking. ',
 
3076
    help='A format that allows a branch to indicate that there is another '
 
3077
         '(stacked) repository that should be used to access data that is '
 
3078
         'not present locally.',
3044
3079
    branch_format='bzrlib.branch.BzrBranchFormat7',
3045
3080
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3046
3081
    )
3047
3082
format_registry.register_metadir('1.6.1-rich-root',
3048
3083
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3049
 
    help='A branch and pack based repository that supports stacking '
3050
 
         'and rich root data (needed for bzr-svn). ',
 
3084
    help='A variant of 1.6 that supports rich-root data '
 
3085
         '(needed for bzr-svn).',
3051
3086
    branch_format='bzrlib.branch.BzrBranchFormat7',
3052
3087
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3053
3088
    )
3054
3089
format_registry.register_metadir('1.9',
3055
3090
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3056
 
    help='A branch and pack based repository that uses btree indexes. ',
 
3091
    help='A repository format using B+tree indexes. These indexes '
 
3092
         'are smaller in size, have smarter caching and provide faster '
 
3093
         'performance for most operations.',
3057
3094
    branch_format='bzrlib.branch.BzrBranchFormat7',
3058
3095
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3059
3096
    )
3060
3097
format_registry.register_metadir('1.9-rich-root',
3061
3098
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3062
 
    help='A branch and pack based repository that uses btree indexes '
3063
 
         'and rich root data (needed for bzr-svn). ',
 
3099
    help='A variant of 1.9 that supports rich-root data '
 
3100
         '(needed for bzr-svn).',
3064
3101
    branch_format='bzrlib.branch.BzrBranchFormat7',
3065
3102
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3066
3103
    )
 
3104
format_registry.register_metadir('1.12-preview',
 
3105
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
 
3106
    help='A working-tree format that supports views and content filtering.',
 
3107
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3108
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
3109
    experimental=True,
 
3110
    )
 
3111
format_registry.register_metadir('1.12-preview-rich-root',
 
3112
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
 
3113
    help='A variant of 1.12-preview that supports rich-root data '
 
3114
         '(needed for bzr-svn).',
 
3115
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3116
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
3117
    experimental=True,
 
3118
    )
3067
3119
# The following two formats should always just be aliases.
3068
3120
format_registry.register_metadir('development',
3069
3121
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',