~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: 2006-02-22 06:19:39 UTC
  • mfrom: (1563.1.5 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060222061939-b4b7825d1d580ccf
Merge in ui for creating and converting to knit branch - no backend support yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
371
371
        :param format: Optional parameter indicating a specific desired
372
372
                       format we plan to arrive at.
373
373
        """
374
 
        # for now, if the format is not the same as the system default,
375
 
        # an upgrade is needed. In the future we will want to scan
376
 
        # the individual repository/branch/checkout formats too
377
 
        if format is None:
378
 
            format = BzrDirFormat.get_default_format().__class__
379
 
        return not isinstance(self._format, format)
 
374
        raise NotImplementedError(self.needs_format_conversion)
380
375
 
381
376
    @staticmethod
382
377
    def open_unsupported(base):
608
603
            return self.transport
609
604
        raise errors.IncompatibleFormat(workingtree_format, self._format)
610
605
 
 
606
    def needs_format_conversion(self, format=None):
 
607
        """See BzrDir.needs_format_conversion()."""
 
608
        # if the format is not the same as the system default,
 
609
        # an upgrade is needed.
 
610
        if format is None:
 
611
            format = BzrDirFormat.get_default_format()
 
612
        return not isinstance(self._format, format.__class__)
 
613
 
611
614
    def open_branch(self, unsupported=False):
612
615
        """See BzrDir.open_branch."""
613
616
        from bzrlib.branch import BzrBranchFormat4
645
648
 
646
649
    def create_repository(self, shared=False):
647
650
        """See BzrDir.create_repository."""
648
 
        from bzrlib.repository import RepositoryFormat4
649
 
        return RepositoryFormat4().initialize(self, shared)
 
651
        return self._format.repository_format.initialize(self, shared)
650
652
 
651
653
    def needs_format_conversion(self, format=None):
652
654
        """Format 4 dirs are always in need of conversion."""
701
703
 
702
704
    def can_convert_format(self):
703
705
        """See BzrDir.can_convert_format()."""
704
 
        return False
 
706
        return True
705
707
 
706
708
    def create_branch(self):
707
709
        """See BzrDir.create_branch."""
710
712
 
711
713
    def create_repository(self, shared=False):
712
714
        """See BzrDir.create_repository."""
713
 
        from bzrlib.repository import RepositoryFormat
714
 
        return RepositoryFormat.get_default_format().initialize(self, shared)
 
715
        return self._format.repository_format.initialize(self, shared)
715
716
 
716
717
    def create_workingtree(self, revision_id=None):
717
718
        """See BzrDir.create_workingtree."""
762
763
 
763
764
    def needs_format_conversion(self, format=None):
764
765
        """See BzrDir.needs_format_conversion()."""
765
 
        # currently there are no possible conversions for meta1 formats.
 
766
        if format is None:
 
767
            format = BzrDirFormat.get_default_format()
 
768
        if not isinstance(self._format, format.__class__):
 
769
            # it is not a meta dir format, conversion is needed.
 
770
            return True
 
771
        # we might want to push this down to the repository?
 
772
        try:
 
773
            if not isinstance(self.open_repository()._format,
 
774
                              format.repository_format.__class__):
 
775
                # the repository needs an upgrade.
 
776
                return True
 
777
        except errors.NoRepositoryPresent:
 
778
            pass
 
779
        # currently there are no other possible conversions for meta1 formats.
766
780
        return False
767
781
 
768
782
    def open_branch(self, unsupported=False):
958
972
        """See BzrDirFormat._open."""
959
973
        return BzrDir4(transport, self)
960
974
 
 
975
    def __return_repository_format(self):
 
976
        """Circular import protection."""
 
977
        from bzrlib.repository import RepositoryFormat4
 
978
        return RepositoryFormat4(self)
 
979
    repository_format = property(__return_repository_format)
 
980
 
961
981
 
962
982
class BzrDirFormat5(BzrDirFormat):
963
983
    """Bzr control format 5.
998
1018
        """See BzrDirFormat._open."""
999
1019
        return BzrDir5(transport, self)
1000
1020
 
 
1021
    def __return_repository_format(self):
 
1022
        """Circular import protection."""
 
1023
        from bzrlib.repository import RepositoryFormat5
 
1024
        return RepositoryFormat5(self)
 
1025
    repository_format = property(__return_repository_format)
 
1026
 
1001
1027
 
1002
1028
class BzrDirFormat6(BzrDirFormat):
1003
1029
    """Bzr control format 6.
1042
1068
        """See BzrDirFormat._open."""
1043
1069
        return BzrDir6(transport, self)
1044
1070
 
 
1071
    def __return_repository_format(self):
 
1072
        """Circular import protection."""
 
1073
        from bzrlib.repository import RepositoryFormat6
 
1074
        return RepositoryFormat6(self)
 
1075
    repository_format = property(__return_repository_format)
 
1076
 
1045
1077
 
1046
1078
class BzrDirMetaFormat1(BzrDirFormat):
1047
1079
    """Bzr meta control format 1
1054
1086
     - Format 7 repositories [optional]
1055
1087
    """
1056
1088
 
 
1089
    def get_converter(self, format=None):
 
1090
        """See BzrDirFormat.get_converter()."""
 
1091
        if format is None:
 
1092
            format = BzrDirFormat.get_default_format()
 
1093
        if not isinstance(self, format.__class__):
 
1094
            # converting away from metadir is not implemented
 
1095
            raise NotImplementedError(self.get_converter)
 
1096
        return ConvertMetaToMeta(format)
 
1097
 
1057
1098
    def get_format_string(self):
1058
1099
        """See BzrDirFormat.get_format_string()."""
1059
1100
        return "Bazaar-NG meta directory, format 1\n"
1062
1103
        """See BzrDirFormat._open."""
1063
1104
        return BzrDirMeta1(transport, self)
1064
1105
 
 
1106
    def __return_repository_format(self):
 
1107
        """Circular import protection."""
 
1108
        if getattr(self, '_repository_format', None):
 
1109
            return self._repository_format
 
1110
        from bzrlib.repository import RepositoryFormat
 
1111
        return RepositoryFormat.get_default_format()
 
1112
 
 
1113
    def __set_repository_format(self, value):
 
1114
        """Allow changint the repository format for metadir formats."""
 
1115
        self._repository_format = value
 
1116
    repository_format = property(__return_repository_format, __set_repository_format)
 
1117
 
1065
1118
 
1066
1119
BzrDirFormat.register_format(BzrDirFormat4())
1067
1120
BzrDirFormat.register_format(BzrDirFormat5())
1176
1229
        :param pb: a progress bar to use for progress information.
1177
1230
        """
1178
1231
 
 
1232
    def step(self, message):
 
1233
        """Update the pb by a step."""
 
1234
        self.count +=1
 
1235
        self.pb.update(message, self.count, self.total)
 
1236
 
1179
1237
 
1180
1238
class ConvertBzrDir4To5(Converter):
1181
1239
    """Converts format 4 bzr dirs to format 5."""
1561
1619
    def put_format(self, dirname, format):
1562
1620
        self.bzrdir._control_files.put_utf8('%s/format' % dirname, format.get_format_string())
1563
1621
 
1564
 
    def step(self, message):
1565
 
        """Update the pb by a step."""
1566
 
        self.count +=1
1567
 
        self.pb.update('Upgrading repository  ', self.count, self.total)
1568
 
 
 
1622
 
 
1623
class ConvertMetaToMeta(Converter):
 
1624
    """Converts the components of metadirs."""
 
1625
 
 
1626
    def __init__(self, target_format):
 
1627
        """Create a metadir to metadir converter.
 
1628
 
 
1629
        :param target_format: The final metadir format that is desired.
 
1630
        """
 
1631
        self.target_format = target_format
 
1632
 
 
1633
    def convert(self, to_convert, pb):
 
1634
        """See Converter.convert()."""
 
1635
        self.bzrdir = to_convert
 
1636
        self.pb = pb
 
1637
        self.count = 0
 
1638
        self.total = 1
 
1639
        self.step('checking repository format')
 
1640
        try:
 
1641
            repo = self.bzrdir.open_repository()
 
1642
        except errors.NoRepositoryPresent:
 
1643
            pass
 
1644
        else:
 
1645
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
 
1646
                from bzrlib.repository import CopyConverter
 
1647
                self.pb.note('starting repository conversion')
 
1648
                converter = CopyConverter(self.target_format.repository_format)
 
1649
                converter.convert(repo, pb)
 
1650
        return to_convert