99
99
def _open_hook(self):
100
100
"""Called by init to allow simpler extension of the base class."""
102
def _activate_fallback_location(self, url):
103
"""Activate the branch/repository from url as a fallback repository."""
104
self.repository.add_fallback_repository(
105
self._get_fallback_repository(url))
102
107
def break_lock(self):
103
108
"""Break a lock if one is present from another instance.
113
118
if master is not None:
114
119
master.break_lock()
121
def _check_stackable_repo(self):
122
if not self.repository._format.supports_external_lookups:
123
raise errors.UnstackableRepositoryFormat(self.repository._format,
124
self.repository.base)
117
127
def open(base, _unsupported=False, possible_transports=None):
118
128
"""Open the branch rooted at base.
157
167
def get_config(self):
158
168
return BranchConfig(self)
170
def _get_fallback_repository(self, url):
171
"""Get the repository we fallback to at url."""
172
url = urlutils.join(self.base, url)
173
a_bzrdir = bzrdir.BzrDir.open(url,
174
possible_transports=[self.bzrdir.root_transport])
175
return a_bzrdir.open_branch().repository
160
177
def _get_tags_bytes(self):
161
178
"""Get the bytes of a serialised tags dict.
569
586
:raises UnstackableRepositoryFormat: If the repository does not support
572
raise NotImplementedError(self.set_stacked_on_url)
589
if not self._format.supports_stacking():
590
raise errors.UnstackableBranchFormat(self._format, self.base)
591
self._check_stackable_repo()
594
old_url = self.get_stacked_on_url()
595
except (errors.NotStacked, errors.UnstackableBranchFormat,
596
errors.UnstackableRepositoryFormat):
599
# repositories don't offer an interface to remove fallback
600
# repositories today; take the conceptually simpler option and just
602
self.repository = self.bzrdir.find_repository()
603
# for every revision reference the branch has, ensure it is pulled
605
source_repository = self._get_fallback_repository(old_url)
606
for revision_id in chain([self.last_revision()],
607
self.tags.get_reverse_tag_dict()):
608
self.repository.fetch(source_repository, revision_id,
611
self._activate_fallback_location(url)
612
# write this out after the repository is stacked to avoid setting a
613
# stacked config that doesn't work.
614
self._set_config_location('stacked_on_location', url)
574
617
def _set_tags_bytes(self, bytes):
575
618
"""Mirror method for _get_tags_bytes.
2161
2204
self._transport.put_bytes('parent', url + '\n',
2162
2205
mode=self.bzrdir._get_file_mode())
2164
def set_stacked_on_url(self, url):
2165
raise errors.UnstackableBranchFormat(self._format, self.base)
2168
2208
class BzrBranch5(BzrBranch):
2169
2209
"""A format 5 branch. This supports new features over plain branches.
2295
2335
class BzrBranch7(BzrBranch5):
2296
2336
"""A branch with support for a fallback repository."""
2298
def _get_fallback_repository(self, url):
2299
"""Get the repository we fallback to at url."""
2300
url = urlutils.join(self.base, url)
2301
a_bzrdir = bzrdir.BzrDir.open(url,
2302
possible_transports=[self._transport])
2303
return a_bzrdir.open_branch().repository
2305
def _activate_fallback_location(self, url):
2306
"""Activate the branch/repository from url as a fallback repository."""
2307
self.repository.add_fallback_repository(
2308
self._get_fallback_repository(url))
2310
2338
def _open_hook(self):
2311
2339
if self._ignore_fallbacks:
2325
2353
"None, not a URL." % hook_name)
2326
2354
self._activate_fallback_location(url)
2328
def _check_stackable_repo(self):
2329
if not self.repository._format.supports_external_lookups:
2330
raise errors.UnstackableRepositoryFormat(self.repository._format,
2331
self.repository.base)
2333
2356
def __init__(self, *args, **kwargs):
2334
2357
self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2335
2358
super(BzrBranch7, self).__init__(*args, **kwargs)
2510
2533
self.get_config().set_user_option('append_revisions_only', value,
2511
2534
warn_masked=True)
2513
def set_stacked_on_url(self, url):
2514
self._check_stackable_repo()
2517
old_url = self.get_stacked_on_url()
2518
except (errors.NotStacked, errors.UnstackableBranchFormat,
2519
errors.UnstackableRepositoryFormat):
2522
# repositories don't offer an interface to remove fallback
2523
# repositories today; take the conceptually simpler option and just
2525
self.repository = self.bzrdir.find_repository()
2526
# for every revision reference the branch has, ensure it is pulled
2528
source_repository = self._get_fallback_repository(old_url)
2529
for revision_id in chain([self.last_revision()],
2530
self.tags.get_reverse_tag_dict()):
2531
self.repository.fetch(source_repository, revision_id,
2534
self._activate_fallback_location(url)
2535
# write this out after the repository is stacked to avoid setting a
2536
# stacked config that doesn't work.
2537
self._set_config_location('stacked_on_location', url)
2539
2536
def _get_append_revisions_only(self):
2540
2537
value = self.get_config().get_user_option('append_revisions_only')
2541
2538
return value == 'True'
2594
2591
def get_stacked_on_url(self):
2595
2592
raise errors.UnstackableBranchFormat(self._format, self.base)
2597
def set_stacked_on_url(self, url):
2598
raise errors.UnstackableBranchFormat(self._format, self.base)
2601
2595
######################################################################
2602
2596
# results of operations