/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Create basic stackable branch facility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
350
350
        """
351
351
        raise NotImplementedError(self.get_root_id)
352
352
 
 
353
    def get_stacked_on(self):
 
354
        """Get the URL this branch is stacked against.
 
355
 
 
356
        :raises NotStacked: If the branch is not stacked.
 
357
        :raises UnstackableBranchFormat: If the branch does not support
 
358
            stacking.
 
359
        """
 
360
        raise NotImplementedError(self.get_stacked_on)
 
361
 
353
362
    def print_file(self, file, revision_id):
354
363
        """Print `file` to stdout."""
355
364
        raise NotImplementedError(self.print_file)
357
366
    def set_revision_history(self, rev_history):
358
367
        raise NotImplementedError(self.set_revision_history)
359
368
 
 
369
    def set_stacked_on(self, url):
 
370
        """set the URL this branch is stacked against.
 
371
 
 
372
        :raises UnstackableBranchFormat: If the branch does not support
 
373
            stacking.
 
374
        :raises UnstackableRepositoryFormat: If the repository does not support
 
375
            stacking.
 
376
        """
 
377
        raise NotImplementedError(self.set_stacked_on)
 
378
 
360
379
    def _cache_revision_history(self, rev_history):
361
380
        """Set the cached revision history to rev_history.
362
381
 
1087
1106
        return "Bazaar-NG branch format 4"
1088
1107
 
1089
1108
 
1090
 
class BzrBranchFormat5(BranchFormat):
 
1109
class BranchFormatMetadir(BranchFormat):
 
1110
    """Common logic for meta-dir based branch formats."""
 
1111
 
 
1112
    def _branch_class(self):
 
1113
        """What class to instantiate on open calls."""
 
1114
        raise NotImplementedError(self._branch_class)
 
1115
 
 
1116
    def open(self, a_bzrdir, _found=False):
 
1117
        """Return the branch object for a_bzrdir
 
1118
 
 
1119
        _found is a private parameter, do not use it. It is used to indicate
 
1120
               if format probing has already be done.
 
1121
        """
 
1122
        if not _found:
 
1123
            format = BranchFormat.find_format(a_bzrdir)
 
1124
            assert format.__class__ == self.__class__
 
1125
        try:
 
1126
            transport = a_bzrdir.get_branch_transport(None)
 
1127
            control_files = lockable_files.LockableFiles(transport, 'lock',
 
1128
                                                         lockdir.LockDir)
 
1129
            return self._branch_class()(_format=self,
 
1130
                              _control_files=control_files,
 
1131
                              a_bzrdir=a_bzrdir,
 
1132
                              _repository=a_bzrdir.find_repository())
 
1133
        except NoSuchFile:
 
1134
            raise NotBranchError(path=transport.base)
 
1135
 
 
1136
    def __init__(self):
 
1137
        super(BranchFormatMetadir, self).__init__()
 
1138
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
 
1139
 
 
1140
    def supports_tags(self):
 
1141
        return True
 
1142
 
 
1143
 
 
1144
class BzrBranchFormat5(BranchFormatMetadir):
1091
1145
    """Bzr branch format 5.
1092
1146
 
1093
1147
    This format has:
1100
1154
    This format is new in bzr 0.8.
1101
1155
    """
1102
1156
 
 
1157
    def _branch_class(self):
 
1158
        return BzrBranch5
 
1159
 
1103
1160
    def get_format_string(self):
1104
1161
        """See BranchFormat.get_format_string()."""
1105
1162
        return "Bazaar-NG branch format 5\n"
1115
1172
                      ]
1116
1173
        return self._initialize_helper(a_bzrdir, utf8_files)
1117
1174
 
1118
 
    def __init__(self):
1119
 
        super(BzrBranchFormat5, self).__init__()
1120
 
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1121
 
 
1122
 
    def open(self, a_bzrdir, _found=False):
1123
 
        """Return the branch object for a_bzrdir
1124
 
 
1125
 
        _found is a private parameter, do not use it. It is used to indicate
1126
 
               if format probing has already be done.
1127
 
        """
1128
 
        if not _found:
1129
 
            format = BranchFormat.find_format(a_bzrdir)
1130
 
            assert format.__class__ == self.__class__
1131
 
        try:
1132
 
            transport = a_bzrdir.get_branch_transport(None)
1133
 
            control_files = lockable_files.LockableFiles(transport, 'lock',
1134
 
                                                         lockdir.LockDir)
1135
 
            return BzrBranch5(_format=self,
1136
 
                              _control_files=control_files,
1137
 
                              a_bzrdir=a_bzrdir,
1138
 
                              _repository=a_bzrdir.find_repository())
1139
 
        except NoSuchFile:
1140
 
            raise NotBranchError(path=transport.base)
1141
 
 
1142
 
 
1143
 
class BzrBranchFormat6(BzrBranchFormat5):
 
1175
    def supports_tags(self):
 
1176
        return False
 
1177
 
 
1178
 
 
1179
class BzrBranchFormat6(BranchFormatMetadir):
1144
1180
    """Branch format with last-revision and tags.
1145
1181
 
1146
1182
    Unlike previous formats, this has no explicit revision history. Instead,
1151
1187
    and became the default in 0.91.
1152
1188
    """
1153
1189
 
 
1190
    def _branch_class(self):
 
1191
        return BzrBranch6
 
1192
 
1154
1193
    def get_format_string(self):
1155
1194
        """See BranchFormat.get_format_string()."""
1156
1195
        return "Bazaar Branch Format 6 (bzr 0.15)\n"
1167
1206
                      ]
1168
1207
        return self._initialize_helper(a_bzrdir, utf8_files)
1169
1208
 
1170
 
    def open(self, a_bzrdir, _found=False):
1171
 
        """Return the branch object for a_bzrdir
1172
 
 
1173
 
        _found is a private parameter, do not use it. It is used to indicate
1174
 
               if format probing has already be done.
1175
 
        """
1176
 
        if not _found:
1177
 
            format = BranchFormat.find_format(a_bzrdir)
1178
 
            assert format.__class__ == self.__class__
1179
 
        transport = a_bzrdir.get_branch_transport(None)
1180
 
        control_files = lockable_files.LockableFiles(transport, 'lock',
1181
 
                                                     lockdir.LockDir)
1182
 
        return BzrBranch6(_format=self,
1183
 
                          _control_files=control_files,
1184
 
                          a_bzrdir=a_bzrdir,
1185
 
                          _repository=a_bzrdir.find_repository())
1186
 
 
1187
 
    def supports_tags(self):
1188
 
        return True
 
1209
 
 
1210
class BzrBranchFormat7(BranchFormatMetadir):
 
1211
    """Branch format with last-revision, tags, and a stacked location pointer.
 
1212
 
 
1213
    The stacked location pointer is passed down to the repository and requires
 
1214
    a repository format with supports_external_lookups = True.
 
1215
 
 
1216
    This format was introduced in bzr 1.3.
 
1217
    """
 
1218
 
 
1219
    def _branch_class(self):
 
1220
        return BzrBranch7
 
1221
 
 
1222
    def get_format_string(self):
 
1223
        """See BranchFormat.get_format_string()."""
 
1224
        return "Bazaar Branch Format 7 (needs bzr 1.3)\n"
 
1225
 
 
1226
    def get_format_description(self):
 
1227
        """See BranchFormat.get_format_description()."""
 
1228
        return "Branch format 7"
 
1229
 
 
1230
    def initialize(self, a_bzrdir):
 
1231
        """Create a branch of this format in a_bzrdir."""
 
1232
        utf8_files = [('last-revision', '0 null:\n'),
 
1233
                      ('branch.conf', ''),
 
1234
                      ('tags', ''),
 
1235
                      ('stacked-on', '\n'),
 
1236
                      ]
 
1237
        return self._initialize_helper(a_bzrdir, utf8_files)
1189
1238
 
1190
1239
 
1191
1240
class BranchReferenceFormat(BranchFormat):
1277
1326
# and not independently creatable, so are not registered.
1278
1327
__format5 = BzrBranchFormat5()
1279
1328
__format6 = BzrBranchFormat6()
 
1329
__format7 = BzrBranchFormat7()
1280
1330
BranchFormat.register_format(__format5)
1281
1331
BranchFormat.register_format(BranchReferenceFormat())
1282
1332
BranchFormat.register_format(__format6)
 
1333
BranchFormat.register_format(__format7)
1283
1334
BranchFormat.set_default_format(__format6)
1284
1335
_legacy_formats = [BzrBranchFormat4(),
1285
1336
                   ]
1653
1704
        except errors.InvalidURLJoin, e:
1654
1705
            raise errors.InaccessibleParent(parent, self.base)
1655
1706
 
 
1707
    def get_stacked_on(self):
 
1708
        raise errors.UnstackableBranchFormat(self._format, self.base)
 
1709
 
1656
1710
    def set_push_location(self, location):
1657
1711
        """See Branch.set_push_location."""
1658
1712
        self.get_config().set_user_option(
1685
1739
            assert isinstance(url, str)
1686
1740
            self.control_files.put_bytes('parent', url + '\n')
1687
1741
 
 
1742
    def set_stacked_on(self, url):
 
1743
        raise errors.UnstackableBranchFormat(self._format, self.base)
 
1744
 
1688
1745
 
1689
1746
class BzrBranch5(BzrBranch):
1690
1747
    """A format 5 branch. This supports new features over plain branches.
1820
1877
        return None
1821
1878
 
1822
1879
 
1823
 
class BzrBranch6(BzrBranch5):
 
1880
class BzrBranch7(BzrBranch5):
 
1881
 
 
1882
    def _check_stackable_repo(self):
 
1883
        if not self.repository._format.supports_external_lookups:
 
1884
            raise errors.UnstackableRepositoryFormat(self.repository._format,
 
1885
                self.repository.base)
1824
1886
 
1825
1887
    @needs_read_lock
1826
1888
    def last_revision_info(self):
1930
1992
        """See Branch.get_old_bound_location"""
1931
1993
        return self._get_bound_location(False)
1932
1994
 
 
1995
    def get_stacked_on(self):
 
1996
        self._check_stackable_repo()
 
1997
 
1933
1998
    def set_append_revisions_only(self, enabled):
1934
1999
        if enabled:
1935
2000
            value = 'True'
1938
2003
        self.get_config().set_user_option('append_revisions_only', value,
1939
2004
            warn_masked=True)
1940
2005
 
 
2006
    def set_stacked_on(self, url):
 
2007
        self._check_stackable_repo()
 
2008
 
1941
2009
    def _get_append_revisions_only(self):
1942
2010
        value = self.get_config().get_user_option('append_revisions_only')
1943
2011
        return value == 'True'
1975
2043
        return BasicTags(self)
1976
2044
 
1977
2045
 
 
2046
class BzrBranch6(BzrBranch7):
 
2047
    """See BzrBranchFormat6 for the capabilities of this branch.
 
2048
 
 
2049
    This subclass of BzrBranch7 disables the new features BzrBranch7 added.
 
2050
    """
 
2051
 
 
2052
    def get_stacked_on(self):
 
2053
        raise errors.UnstackableBranchFormat(self._format, self.base)
 
2054
 
 
2055
    def set_stacked_on(self, url):
 
2056
        raise errors.UnstackableBranchFormat(self._format, self.base)
 
2057
 
 
2058
 
1978
2059
######################################################################
1979
2060
# results of operations
1980
2061