~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Ian Clatworthy
  • Date: 2010-02-19 03:02:07 UTC
  • mto: (4797.23.1 integration-2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: ian.clatworthy@canonical.com-20100219030207-zpbzx021zavx4sqt
What's New in 2.1 - a summary of changes since 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
77
77
from bzrlib.trace import (
78
78
    mutter,
79
79
    note,
 
80
    warning,
80
81
    )
81
82
 
82
83
from bzrlib import (
128
129
        return True
129
130
 
130
131
    def check_conversion_target(self, target_format):
 
132
        """Check that a bzrdir as a whole can be converted to a new format."""
 
133
        # The only current restriction is that the repository content can be 
 
134
        # fetched compatibly with the target.
131
135
        target_repo_format = target_format.repository_format
132
 
        source_repo_format = self._format.repository_format
133
 
        source_repo_format.check_conversion_target(target_repo_format)
 
136
        try:
 
137
            self.open_repository()._format.check_conversion_target(
 
138
                target_repo_format)
 
139
        except errors.NoRepositoryPresent:
 
140
            # No repo, no problem.
 
141
            pass
134
142
 
135
143
    @staticmethod
136
144
    def _check_supported(format, allow_unsupported,
576
584
            # permissions as the .bzr directory (probably a bug in copy_tree)
577
585
            old_path = self.root_transport.abspath('.bzr')
578
586
            new_path = self.root_transport.abspath('backup.bzr')
579
 
            pb.note('making backup of %s' % (old_path,))
580
 
            pb.note('  to %s' % (new_path,))
 
587
            ui.ui_factory.note('making backup of %s\n  to %s' % (old_path, new_path,))
581
588
            self.root_transport.copy_tree('.bzr', 'backup.bzr')
582
589
            return (old_path, new_path)
583
590
        finally:
1384
1391
        # that can do wonky stuff here, and that only
1385
1392
        # happens for creating checkouts, which cannot be
1386
1393
        # done on this format anyway. So - acceptable wart.
 
1394
        if hardlink:
 
1395
            warning("can't support hardlinked working trees in %r"
 
1396
                % (self,))
1387
1397
        try:
1388
1398
            result = self.open_workingtree(recommend_upgrade=False)
1389
1399
        except errors.NoSuchFile:
1526
1536
    This is a deprecated format and may be removed after sept 2006.
1527
1537
    """
1528
1538
 
 
1539
    def has_workingtree(self):
 
1540
        """See BzrDir.has_workingtree."""
 
1541
        return True
 
1542
    
1529
1543
    def open_repository(self):
1530
1544
        """See BzrDir.open_repository."""
1531
1545
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1547
1561
    This is a deprecated format and may be removed after sept 2006.
1548
1562
    """
1549
1563
 
 
1564
    def has_workingtree(self):
 
1565
        """See BzrDir.has_workingtree."""
 
1566
        return True
 
1567
    
1550
1568
    def open_repository(self):
1551
1569
        """See BzrDir.open_repository."""
1552
1570
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1630
1648
 
1631
1649
    def get_branch_transport(self, branch_format):
1632
1650
        """See BzrDir.get_branch_transport()."""
 
1651
        # XXX: this shouldn't implicitly create the directory if it's just
 
1652
        # promising to get a transport -- mbp 20090727
1633
1653
        if branch_format is None:
1634
1654
            return self.transport.clone('branch')
1635
1655
        try:
1670
1690
            pass
1671
1691
        return self.transport.clone('checkout')
1672
1692
 
 
1693
    def has_workingtree(self):
 
1694
        """Tell if this bzrdir contains a working tree.
 
1695
 
 
1696
        This will still raise an exception if the bzrdir has a workingtree that
 
1697
        is remote & inaccessible.
 
1698
 
 
1699
        Note: if you're going to open the working tree, you should just go
 
1700
        ahead and try, and not ask permission first.
 
1701
        """
 
1702
        from bzrlib.workingtree import WorkingTreeFormat
 
1703
        try:
 
1704
            WorkingTreeFormat.find_format(self)
 
1705
        except errors.NoWorkingTree:
 
1706
            return False
 
1707
        return True
 
1708
 
1673
1709
    def needs_format_conversion(self, format=None):
1674
1710
        """See BzrDir.needs_format_conversion()."""
1675
1711
        if format is None:
1791
1827
    def probe_transport(klass, transport):
1792
1828
        """Return the .bzrdir style format present in a directory."""
1793
1829
        try:
1794
 
            format_string = transport.get(".bzr/branch-format").read()
 
1830
            format_string = transport.get_bytes(".bzr/branch-format")
1795
1831
        except errors.NoSuchFile:
1796
1832
            raise errors.NotBranchError(path=transport.base)
1797
1833
 
2574
2610
        """See Converter.convert()."""
2575
2611
        self.bzrdir = to_convert
2576
2612
        self.pb = pb
2577
 
        self.pb.note('starting upgrade from format 4 to 5')
 
2613
        ui.ui_factory.note('starting upgrade from format 4 to 5')
2578
2614
        if isinstance(self.bzrdir.transport, local.LocalTransport):
2579
2615
            self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
2580
2616
        self._convert_to_weaves()
2581
2617
        return BzrDir.open(self.bzrdir.root_transport.base)
2582
2618
 
2583
2619
    def _convert_to_weaves(self):
2584
 
        self.pb.note('note: upgrade may be faster if all store files are ungzipped first')
 
2620
        ui.ui_factory.note('note: upgrade may be faster if all store files are ungzipped first')
2585
2621
        try:
2586
2622
            # TODO permissions
2587
2623
            stat = self.bzrdir.transport.stat('weaves')
2615
2651
        self.pb.clear()
2616
2652
        self._write_all_weaves()
2617
2653
        self._write_all_revs()
2618
 
        self.pb.note('upgraded to weaves:')
2619
 
        self.pb.note('  %6d revisions and inventories', len(self.revisions))
2620
 
        self.pb.note('  %6d revisions not present', len(self.absent_revisions))
2621
 
        self.pb.note('  %6d texts', self.text_count)
 
2654
        ui.ui_factory.note('upgraded to weaves:')
 
2655
        ui.ui_factory.note('  %6d revisions and inventories' % len(self.revisions))
 
2656
        ui.ui_factory.note('  %6d revisions not present' % len(self.absent_revisions))
 
2657
        ui.ui_factory.note('  %6d texts' % self.text_count)
2622
2658
        self._cleanup_spare_files_after_format4()
2623
2659
        self.branch._transport.put_bytes(
2624
2660
            'branch-format',
2692
2728
                       len(self.known_revisions))
2693
2729
        if not self.branch.repository.has_revision(rev_id):
2694
2730
            self.pb.clear()
2695
 
            self.pb.note('revision {%s} not present in branch; '
2696
 
                         'will be converted as a ghost',
 
2731
            ui.ui_factory.note('revision {%s} not present in branch; '
 
2732
                         'will be converted as a ghost' %
2697
2733
                         rev_id)
2698
2734
            self.absent_revisions.add(rev_id)
2699
2735
        else:
2826
2862
        """See Converter.convert()."""
2827
2863
        self.bzrdir = to_convert
2828
2864
        self.pb = pb
2829
 
        self.pb.note('starting upgrade from format 5 to 6')
 
2865
        ui.ui_factory.note('starting upgrade from format 5 to 6')
2830
2866
        self._convert_to_prefixed()
2831
2867
        return BzrDir.open(self.bzrdir.root_transport.base)
2832
2868
 
2834
2870
        from bzrlib.store import TransportStore
2835
2871
        self.bzrdir.transport.delete('branch-format')
2836
2872
        for store_name in ["weaves", "revision-store"]:
2837
 
            self.pb.note("adding prefixes to %s" % store_name)
 
2873
            ui.ui_factory.note("adding prefixes to %s" % store_name)
2838
2874
            store_transport = self.bzrdir.transport.clone(store_name)
2839
2875
            store = TransportStore(store_transport, prefixed=True)
2840
2876
            for urlfilename in store_transport.list_dir('.'):
2874
2910
        self.dir_mode = self.bzrdir._get_dir_mode()
2875
2911
        self.file_mode = self.bzrdir._get_file_mode()
2876
2912
 
2877
 
        self.pb.note('starting upgrade from format 6 to metadir')
 
2913
        ui.ui_factory.note('starting upgrade from format 6 to metadir')
2878
2914
        self.bzrdir.transport.put_bytes(
2879
2915
                'branch-format',
2880
2916
                "Converting to format 6",
2930
2966
        else:
2931
2967
            has_checkout = True
2932
2968
        if not has_checkout:
2933
 
            self.pb.note('No working tree.')
 
2969
            ui.ui_factory.note('No working tree.')
2934
2970
            # If some checkout files are there, we may as well get rid of them.
2935
2971
            for name, mandatory in checkout_files:
2936
2972
                if name in bzrcontents:
3005
3041
        else:
3006
3042
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
3007
3043
                from bzrlib.repository import CopyConverter
3008
 
                self.pb.note('starting repository conversion')
 
3044
                ui.ui_factory.note('starting repository conversion')
3009
3045
                converter = CopyConverter(self.target_format.repository_format)
3010
3046
                converter.convert(repo, pb)
3011
3047
        try:
3033
3069
                      new is _mod_branch.BzrBranchFormat8):
3034
3070
                    branch_converter = _mod_branch.Converter7to8()
3035
3071
                else:
3036
 
                    raise errors.BadConversionTarget("No converter", new)
 
3072
                    raise errors.BadConversionTarget("No converter", new,
 
3073
                        branch._format)
3037
3074
                branch_converter.convert(branch)
3038
3075
                branch = self.bzrdir.open_branch()
3039
3076
                old = branch._format.__class__
3071
3108
 
3072
3109
    def __init__(self):
3073
3110
        BzrDirMetaFormat1.__init__(self)
 
3111
        # XXX: It's a bit ugly that the network name is here, because we'd
 
3112
        # like to believe that format objects are stateless or at least
 
3113
        # immutable,  However, we do at least avoid mutating the name after
 
3114
        # it's returned.  See <https://bugs.edge.launchpad.net/bzr/+bug/504102>
3074
3115
        self._network_name = None
3075
3116
 
 
3117
    def __repr__(self):
 
3118
        return "%s(_network_name=%r)" % (self.__class__.__name__,
 
3119
            self._network_name)
 
3120
 
3076
3121
    def get_format_description(self):
 
3122
        if self._network_name:
 
3123
            real_format = network_format_registry.get(self._network_name)
 
3124
            return 'Remote: ' + real_format.get_format_description()
3077
3125
        return 'bzr remote bzrdir'
3078
3126
 
3079
3127
    def get_format_string(self):
3212
3260
        args.append(self._serialize_NoneString(repo_format_name))
3213
3261
        args.append(self._serialize_NoneTrueFalse(make_working_trees))
3214
3262
        args.append(self._serialize_NoneTrueFalse(shared_repo))
3215
 
        if self._network_name is None:
3216
 
            self._network_name = \
 
3263
        request_network_name = self._network_name or \
3217
3264
            BzrDirFormat.get_default_format().network_name()
3218
3265
        try:
3219
3266
            response = client.call('BzrDirFormat.initialize_ex_1.16',
3220
 
                self.network_name(), path, *args)
 
3267
                request_network_name, path, *args)
3221
3268
        except errors.UnknownSmartMethod:
3222
3269
            client._medium._remember_remote_is_before((1,16))
3223
3270
            local_dir_format = BzrDirMetaFormat1()
3473
3520
                experimental_pairs.append((key, help))
3474
3521
            else:
3475
3522
                output += wrapped(key, help, info)
3476
 
        output += "\nSee ``bzr help formats`` for more about storage formats."
 
3523
        output += "\nSee :doc:`formats-help` for more about storage formats."
3477
3524
        other_output = ""
3478
3525
        if len(experimental_pairs) > 0:
3479
3526
            other_output += "Experimental formats are shown below.\n\n"
3492
3539
            other_output += \
3493
3540
                "\nNo deprecated formats are available.\n\n"
3494
3541
        other_output += \
3495
 
            "\nSee ``bzr help formats`` for more about storage formats."
 
3542
                "\nSee :doc:`formats-help` for more about storage formats."
3496
3543
 
3497
3544
        if topic == 'other-formats':
3498
3545
            return other_output
3542
3589
            if self._require_stacking:
3543
3590
                raise
3544
3591
 
 
3592
    def requires_stacking(self):
 
3593
        """Return True if this policy requires stacking."""
 
3594
        return self._stack_on is not None and self._require_stacking
 
3595
 
3545
3596
    def _get_full_stack_on(self):
3546
3597
        """Get a fully-qualified URL for the stack_on location."""
3547
3598
        if self._stack_on is None:
3663
3714
format_registry.register('weave', BzrDirFormat6,
3664
3715
    'Pre-0.8 format.  Slower than knit and does not'
3665
3716
    ' support checkouts or shared repositories.',
 
3717
    hidden=True,
3666
3718
    deprecated=True)
3667
3719
format_registry.register_metadir('metaweave',
3668
3720
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3669
3721
    'Transitional format in 0.8.  Slower than knit.',
3670
3722
    branch_format='bzrlib.branch.BzrBranchFormat5',
3671
3723
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
 
3724
    hidden=True,
3672
3725
    deprecated=True)
3673
3726
format_registry.register_metadir('knit',
3674
3727
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3675
3728
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
3676
3729
    branch_format='bzrlib.branch.BzrBranchFormat5',
3677
3730
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
 
3731
    hidden=True,
3678
3732
    deprecated=True)
3679
3733
format_registry.register_metadir('dirstate',
3680
3734
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3684
3738
    # this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
3685
3739
    # directly from workingtree_4 triggers a circular import.
3686
3740
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3741
    hidden=True,
3687
3742
    deprecated=True)
3688
3743
format_registry.register_metadir('dirstate-tags',
3689
3744
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3692
3747
        ' Incompatible with bzr < 0.15.',
3693
3748
    branch_format='bzrlib.branch.BzrBranchFormat6',
3694
3749
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3750
    hidden=True,
3695
3751
    deprecated=True)
3696
3752
format_registry.register_metadir('rich-root',
3697
3753
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
3699
3755
        ' bzr < 1.0.',
3700
3756
    branch_format='bzrlib.branch.BzrBranchFormat6',
3701
3757
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3758
    hidden=True,
3702
3759
    deprecated=True)
3703
3760
format_registry.register_metadir('dirstate-with-subtree',
3704
3761
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
3740
3797
         '(needed for bzr-svn and bzr-git).',
3741
3798
    branch_format='bzrlib.branch.BzrBranchFormat6',
3742
3799
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3800
    hidden=True,
3743
3801
    )
3744
3802
format_registry.register_metadir('1.6',
3745
3803
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3748
3806
         'not present locally.',
3749
3807
    branch_format='bzrlib.branch.BzrBranchFormat7',
3750
3808
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3809
    hidden=True,
3751
3810
    )
3752
3811
format_registry.register_metadir('1.6.1-rich-root',
3753
3812
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3755
3814
         '(needed for bzr-svn and bzr-git).',
3756
3815
    branch_format='bzrlib.branch.BzrBranchFormat7',
3757
3816
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3817
    hidden=True,
3758
3818
    )
3759
3819
format_registry.register_metadir('1.9',
3760
3820
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3763
3823
         'performance for most operations.',
3764
3824
    branch_format='bzrlib.branch.BzrBranchFormat7',
3765
3825
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3826
    hidden=True,
3766
3827
    )
3767
3828
format_registry.register_metadir('1.9-rich-root',
3768
3829
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3770
3831
         '(needed for bzr-svn and bzr-git).',
3771
3832
    branch_format='bzrlib.branch.BzrBranchFormat7',
3772
3833
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3834
    hidden=True,
3773
3835
    )
3774
3836
format_registry.register_metadir('1.14',
3775
3837
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3797
3859
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3798
3860
    experimental=True,
3799
3861
    alias=True,
 
3862
    hidden=True,
3800
3863
    )
3801
3864
format_registry.register_metadir('development-subtree',
3802
3865
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3809
3872
    branch_format='bzrlib.branch.BzrBranchFormat7',
3810
3873
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3811
3874
    experimental=True,
 
3875
    hidden=True,
3812
3876
    alias=False, # Restore to being an alias when an actual development subtree format is added
3813
3877
                 # This current non-alias status is simply because we did not introduce a
3814
3878
                 # chk based subtree format.
3854
3918
# The following format should be an alias for the rich root equivalent 
3855
3919
# of the default format
3856
3920
format_registry.register_metadir('default-rich-root',
3857
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3858
 
    help='Default format, rich root variant. (needed for bzr-svn and bzr-git).',
3859
 
    branch_format='bzrlib.branch.BzrBranchFormat6',
3860
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3921
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
3922
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3923
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3861
3924
    alias=True,
3862
 
    )
 
3925
    hidden=True,
 
3926
    help='Same as 2a.')
 
3927
 
3863
3928
# The current format that is made on 'bzr init'.
3864
 
format_registry.set_default('pack-0.92')
 
3929
format_registry.set_default('2a')