86
88
self._revision_history_cache = None
87
89
self._revision_id_to_revno_cache = None
88
90
self._last_revision_info_cache = None
94
"""Called by init to allow simpler extension of the base class."""
90
96
def break_lock(self):
91
97
"""Break a lock if one is present from another instance.
325
331
raise errors.InvalidRevisionNumber(revno)
326
332
return self.repository.get_revision_delta(rh[revno-1])
334
def get_stacked_on(self):
335
"""Get the URL this branch is stacked against.
337
:raises NotStacked: If the branch is not stacked.
338
:raises UnstackableBranchFormat: If the branch does not support
341
raise NotImplementedError(self.get_stacked_on)
328
343
def print_file(self, file, revision_id):
329
344
"""Print `file` to stdout."""
330
345
raise NotImplementedError(self.print_file)
332
347
def set_revision_history(self, rev_history):
333
348
raise NotImplementedError(self.set_revision_history)
350
def set_stacked_on(self, url):
351
"""Set the URL this branch is stacked against.
353
:raises UnstackableBranchFormat: If the branch does not support
355
:raises UnstackableRepositoryFormat: If the repository does not support
358
raise NotImplementedError(self.set_stacked_on)
335
360
def _cache_revision_history(self, rev_history):
336
361
"""Set the cached revision history to rev_history.
1207
1232
return "Bazaar-NG branch format 4"
1210
class BzrBranchFormat5(BranchFormat):
1235
class BranchFormatMetadir(BranchFormat):
1236
"""Common logic for meta-dir based branch formats."""
1238
def _branch_class(self):
1239
"""What class to instantiate on open calls."""
1240
raise NotImplementedError(self._branch_class)
1242
def open(self, a_bzrdir, _found=False):
1243
"""Return the branch object for a_bzrdir.
1245
_found is a private parameter, do not use it. It is used to indicate
1246
if format probing has already be done.
1249
format = BranchFormat.find_format(a_bzrdir)
1250
if format.__class__ != self.__class__:
1251
raise AssertionError("wrong format %r found for %r" %
1254
transport = a_bzrdir.get_branch_transport(None)
1255
control_files = lockable_files.LockableFiles(transport, 'lock',
1257
return self._branch_class()(_format=self,
1258
_control_files=control_files,
1260
_repository=a_bzrdir.find_repository())
1261
except errors.NoSuchFile:
1262
raise errors.NotBranchError(path=transport.base)
1265
super(BranchFormatMetadir, self).__init__()
1266
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1268
def supports_tags(self):
1272
class BzrBranchFormat5(BranchFormatMetadir):
1211
1273
"""Bzr branch format 5.
1213
1275
This format has:
1236
1301
return self._initialize_helper(a_bzrdir, utf8_files)
1239
super(BzrBranchFormat5, self).__init__()
1240
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1242
def open(self, a_bzrdir, _found=False):
1243
"""Return the branch object for a_bzrdir
1245
_found is a private parameter, do not use it. It is used to indicate
1246
if format probing has already be done.
1249
format = BranchFormat.find_format(a_bzrdir)
1250
if format.__class__ != self.__class__:
1251
raise AssertionError("wrong format %r found for %r" %
1254
transport = a_bzrdir.get_branch_transport(None)
1255
control_files = lockable_files.LockableFiles(transport, 'lock',
1257
return BzrBranch5(_format=self,
1258
_control_files=control_files,
1260
_repository=a_bzrdir.find_repository())
1261
except errors.NoSuchFile:
1262
raise errors.NotBranchError(path=transport.base)
1265
class BzrBranchFormat6(BzrBranchFormat5):
1303
def supports_tags(self):
1307
class BzrBranchFormat6(BranchFormatMetadir):
1266
1308
"""Branch format with last-revision and tags.
1268
1310
Unlike previous formats, this has no explicit revision history. Instead,
1290
1335
return self._initialize_helper(a_bzrdir, utf8_files)
1292
def open(self, a_bzrdir, _found=False):
1293
"""Return the branch object for a_bzrdir
1295
_found is a private parameter, do not use it. It is used to indicate
1296
if format probing has already be done.
1299
format = BranchFormat.find_format(a_bzrdir)
1300
if format.__class__ != self.__class__:
1301
raise AssertionError("wrong format %r found for %r" %
1303
transport = a_bzrdir.get_branch_transport(None)
1304
control_files = lockable_files.LockableFiles(transport, 'lock',
1306
return BzrBranch6(_format=self,
1307
_control_files=control_files,
1309
_repository=a_bzrdir.find_repository())
1311
def supports_tags(self):
1338
class BzrBranchFormat7(BranchFormatMetadir):
1339
"""Branch format with last-revision, tags, and a stacked location pointer.
1341
The stacked location pointer is passed down to the repository and requires
1342
a repository format with supports_external_lookups = True.
1344
This format was introduced in bzr 1.6.
1347
def _branch_class(self):
1350
def get_format_string(self):
1351
"""See BranchFormat.get_format_string()."""
1352
return "Bazaar Branch Format 7 (needs bzr 1.6)\n"
1354
def get_format_description(self):
1355
"""See BranchFormat.get_format_description()."""
1356
return "Branch format 7"
1358
def initialize(self, a_bzrdir):
1359
"""Create a branch of this format in a_bzrdir."""
1360
utf8_files = [('last-revision', '0 null:\n'),
1361
('branch.conf', ''),
1364
return self._initialize_helper(a_bzrdir, utf8_files)
1367
super(BzrBranchFormat7, self).__init__()
1368
self._matchingbzrdir.repository_format = \
1369
RepositoryFormatPackDevelopment1Subtree()
1315
1372
class BranchReferenceFormat(BranchFormat):
1403
1460
# and not independently creatable, so are not registered.
1404
1461
__format5 = BzrBranchFormat5()
1405
1462
__format6 = BzrBranchFormat6()
1463
__format7 = BzrBranchFormat7()
1406
1464
BranchFormat.register_format(__format5)
1407
1465
BranchFormat.register_format(BranchReferenceFormat())
1408
1466
BranchFormat.register_format(__format6)
1467
BranchFormat.register_format(__format7)
1409
1468
BranchFormat.set_default_format(__format6)
1410
1469
_legacy_formats = [BzrBranchFormat4(),
1427
1486
def __init__(self, _format=None,
1428
1487
_control_files=None, a_bzrdir=None, _repository=None):
1429
1488
"""Create new branch object at a particular location."""
1430
Branch.__init__(self)
1431
1489
if a_bzrdir is None:
1432
1490
raise ValueError('a_bzrdir must be supplied')
1442
1500
self.control_files = _control_files
1443
1501
self._transport = _control_files._transport
1444
1502
self.repository = _repository
1503
Branch.__init__(self)
1446
1505
def __str__(self):
1447
1506
return '%s(%r)' % (self.__class__.__name__, self.base)
1778
1837
except errors.InvalidURLJoin, e:
1779
1838
raise errors.InaccessibleParent(parent, self.base)
1840
def get_stacked_on(self):
1841
raise errors.UnstackableBranchFormat(self._format, self.base)
1781
1843
def set_push_location(self, location):
1782
1844
"""See Branch.set_push_location."""
1783
1845
self.get_config().set_user_option(
1809
1871
self._transport.put_bytes('parent', url + '\n',
1810
1872
mode=self.bzrdir._get_file_mode())
1874
def set_stacked_on(self, url):
1875
raise errors.UnstackableBranchFormat(self._format, self.base)
1813
1878
class BzrBranch5(BzrBranch):
1814
1879
"""A format 5 branch. This supports new features over plain branches.
1816
1881
It has support for a master_branch which is the data for bound branches.
1824
super(BzrBranch5, self).__init__(_format=_format,
1825
_control_files=_control_files,
1827
_repository=_repository)
1829
1884
@needs_write_lock
1830
1885
def pull(self, source, overwrite=False, stop_revision=None,
1831
1886
run_hooks=True, possible_transports=None,
1950
class BzrBranch6(BzrBranch5):
2005
class BzrBranch7(BzrBranch5):
2006
"""A branch with support for a fallback repository."""
2008
def _get_fallback_repository(self, url):
2009
"""Get the repository we fallback to at url."""
2010
return bzrdir.BzrDir.open(url).open_branch().repository
2012
def _activate_fallback_location(self, url):
2013
"""Activate the branch/repository from url as a fallback repository."""
2014
self.repository.add_fallback_repository(
2015
self._get_fallback_repository(url))
2017
def _open_hook(self):
2019
url = self.get_stacked_on()
2020
except (errors.UnstackableRepositoryFormat, errors.NotStacked,
2021
errors.UnstackableBranchFormat):
2024
self._activate_fallback_location(url)
2026
def _check_stackable_repo(self):
2027
if not self.repository._format.supports_external_lookups:
2028
raise errors.UnstackableRepositoryFormat(self.repository._format,
2029
self.repository.base)
1952
2031
def __init__(self, *args, **kwargs):
1953
super(BzrBranch6, self).__init__(*args, **kwargs)
2032
super(BzrBranch7, self).__init__(*args, **kwargs)
2033
self._last_revision_info_cache = None
1954
2034
self._partial_revision_history_cache = []
1956
2036
def _clear_cached_state(self):
1957
super(BzrBranch6, self)._clear_cached_state()
2037
super(BzrBranch7, self)._clear_cached_state()
2038
self._last_revision_info_cache = None
1958
2039
self._partial_revision_history_cache = []
1960
2041
def _last_revision_info(self):
2097
2178
"""See Branch.get_old_bound_location"""
2098
2179
return self._get_bound_location(False)
2181
def get_stacked_on(self):
2182
self._check_stackable_repo()
2183
stacked_url = self._get_config_location('stacked_on_location')
2184
if stacked_url is None:
2185
raise errors.NotStacked(self)
2100
2188
def set_append_revisions_only(self, enabled):
2105
2193
self.get_config().set_user_option('append_revisions_only', value,
2106
2194
warn_masked=True)
2196
def set_stacked_on(self, url):
2197
self._check_stackable_repo()
2200
old_url = self.get_stacked_on()
2201
except (errors.NotStacked, errors.UnstackableBranchFormat,
2202
errors.UnstackableRepositoryFormat):
2205
# repositories don't offer an interface to remove fallback
2206
# repositories today; take the conceptually simpler option and just
2208
self.repository = self.bzrdir.find_repository()
2209
# for every revision reference the branch has, ensure it is pulled
2211
source_repository = self._get_fallback_repository(old_url)
2212
for revision_id in chain([self.last_revision()],
2213
self.tags.get_reverse_tag_dict()):
2214
self.repository.fetch(source_repository, revision_id,
2217
self._activate_fallback_location(url)
2218
# write this out after the repository is stacked to avoid setting a
2219
# stacked config that doesn't work.
2220
self._set_config_location('stacked_on_location', url)
2108
2222
def _get_append_revisions_only(self):
2109
2223
value = self.get_config().get_user_option('append_revisions_only')
2110
2224
return value == 'True'
2185
2299
return self.revno() - index
2302
class BzrBranch6(BzrBranch7):
2303
"""See BzrBranchFormat6 for the capabilities of this branch.
2305
This subclass of BzrBranch7 disables the new features BzrBranch7 added,
2309
def get_stacked_on(self):
2310
raise errors.UnstackableBranchFormat(self._format, self.base)
2312
def set_stacked_on(self, url):
2313
raise errors.UnstackableBranchFormat(self._format, self.base)
2188
2316
######################################################################
2189
2317
# results of operations
2301
2429
except errors.NoSuchFile:
2303
2431
branch.set_bound_location(None)
2434
class Converter6to7(object):
2435
"""Perform an in-place upgrade of format 6 to format 7"""
2437
def convert(self, branch):
2438
format = BzrBranchFormat7()
2439
branch._set_config_location('stacked_on_location', '')
2440
# update target format
2441
branch._transport.put_bytes('format', format.get_format_string())