351
351
raise NotImplementedError(self.get_root_id)
353
def get_stacked_on(self):
354
"""Get the URL this branch is stacked against.
356
:raises NotStacked: If the branch is not stacked.
357
:raises UnstackableBranchFormat: If the branch does not support
360
raise NotImplementedError(self.get_stacked_on)
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)
369
def set_stacked_on(self, url):
370
"""set the URL this branch is stacked against.
372
:raises UnstackableBranchFormat: If the branch does not support
374
:raises UnstackableRepositoryFormat: If the repository does not support
377
raise NotImplementedError(self.set_stacked_on)
360
379
def _cache_revision_history(self, rev_history):
361
380
"""Set the cached revision history to rev_history.
1087
1106
return "Bazaar-NG branch format 4"
1090
class BzrBranchFormat5(BranchFormat):
1109
class BranchFormatMetadir(BranchFormat):
1110
"""Common logic for meta-dir based branch formats."""
1112
def _branch_class(self):
1113
"""What class to instantiate on open calls."""
1114
raise NotImplementedError(self._branch_class)
1116
def open(self, a_bzrdir, _found=False):
1117
"""Return the branch object for a_bzrdir
1119
_found is a private parameter, do not use it. It is used to indicate
1120
if format probing has already be done.
1123
format = BranchFormat.find_format(a_bzrdir)
1124
assert format.__class__ == self.__class__
1126
transport = a_bzrdir.get_branch_transport(None)
1127
control_files = lockable_files.LockableFiles(transport, 'lock',
1129
return self._branch_class()(_format=self,
1130
_control_files=control_files,
1132
_repository=a_bzrdir.find_repository())
1134
raise NotBranchError(path=transport.base)
1137
super(BranchFormatMetadir, self).__init__()
1138
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1140
def supports_tags(self):
1144
class BzrBranchFormat5(BranchFormatMetadir):
1091
1145
"""Bzr branch format 5.
1093
1147
This format has:
1116
1173
return self._initialize_helper(a_bzrdir, utf8_files)
1119
super(BzrBranchFormat5, self).__init__()
1120
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1122
def open(self, a_bzrdir, _found=False):
1123
"""Return the branch object for a_bzrdir
1125
_found is a private parameter, do not use it. It is used to indicate
1126
if format probing has already be done.
1129
format = BranchFormat.find_format(a_bzrdir)
1130
assert format.__class__ == self.__class__
1132
transport = a_bzrdir.get_branch_transport(None)
1133
control_files = lockable_files.LockableFiles(transport, 'lock',
1135
return BzrBranch5(_format=self,
1136
_control_files=control_files,
1138
_repository=a_bzrdir.find_repository())
1140
raise NotBranchError(path=transport.base)
1143
class BzrBranchFormat6(BzrBranchFormat5):
1175
def supports_tags(self):
1179
class BzrBranchFormat6(BranchFormatMetadir):
1144
1180
"""Branch format with last-revision and tags.
1146
1182
Unlike previous formats, this has no explicit revision history. Instead,
1168
1207
return self._initialize_helper(a_bzrdir, utf8_files)
1170
def open(self, a_bzrdir, _found=False):
1171
"""Return the branch object for a_bzrdir
1173
_found is a private parameter, do not use it. It is used to indicate
1174
if format probing has already be done.
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',
1182
return BzrBranch6(_format=self,
1183
_control_files=control_files,
1185
_repository=a_bzrdir.find_repository())
1187
def supports_tags(self):
1210
class BzrBranchFormat7(BranchFormatMetadir):
1211
"""Branch format with last-revision, tags, and a stacked location pointer.
1213
The stacked location pointer is passed down to the repository and requires
1214
a repository format with supports_external_lookups = True.
1216
This format was introduced in bzr 1.3.
1219
def _branch_class(self):
1222
def get_format_string(self):
1223
"""See BranchFormat.get_format_string()."""
1224
return "Bazaar Branch Format 7 (needs bzr 1.3)\n"
1226
def get_format_description(self):
1227
"""See BranchFormat.get_format_description()."""
1228
return "Branch format 7"
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', ''),
1235
('stacked-on', '\n'),
1237
return self._initialize_helper(a_bzrdir, utf8_files)
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(),
1653
1704
except errors.InvalidURLJoin, e:
1654
1705
raise errors.InaccessibleParent(parent, self.base)
1707
def get_stacked_on(self):
1708
raise errors.UnstackableBranchFormat(self._format, self.base)
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')
1742
def set_stacked_on(self, url):
1743
raise errors.UnstackableBranchFormat(self._format, self.base)
1689
1746
class BzrBranch5(BzrBranch):
1690
1747
"""A format 5 branch. This supports new features over plain branches.
1823
class BzrBranch6(BzrBranch5):
1880
class BzrBranch7(BzrBranch5):
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)
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)
1995
def get_stacked_on(self):
1996
self._check_stackable_repo()
1933
1998
def set_append_revisions_only(self, enabled):
1938
2003
self.get_config().set_user_option('append_revisions_only', value,
1939
2004
warn_masked=True)
2006
def set_stacked_on(self, url):
2007
self._check_stackable_repo()
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)
2046
class BzrBranch6(BzrBranch7):
2047
"""See BzrBranchFormat6 for the capabilities of this branch.
2049
This subclass of BzrBranch7 disables the new features BzrBranch7 added.
2052
def get_stacked_on(self):
2053
raise errors.UnstackableBranchFormat(self._format, self.base)
2055
def set_stacked_on(self, url):
2056
raise errors.UnstackableBranchFormat(self._format, self.base)
1978
2059
######################################################################
1979
2060
# results of operations