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_config(self):
171
"""Get the concrete config for just the config in this branch.
173
This is not intended for client use; see Branch.get_config for the
178
:return: An object supporting get_option and set_option.
180
raise NotImplementedError(self._get_config)
182
def _get_fallback_repository(self, url):
183
"""Get the repository we fallback to at url."""
184
url = urlutils.join(self.base, url)
185
a_bzrdir = bzrdir.BzrDir.open(url,
186
possible_transports=[self.bzrdir.root_transport])
187
return a_bzrdir.open_branch().repository
160
189
def _get_tags_bytes(self):
161
190
"""Get the bytes of a serialised tags dict.
569
598
:raises UnstackableRepositoryFormat: If the repository does not support
572
raise NotImplementedError(self.set_stacked_on_url)
601
if not self._format.supports_stacking():
602
raise errors.UnstackableBranchFormat(self._format, self.base)
603
self._check_stackable_repo()
606
old_url = self.get_stacked_on_url()
607
except (errors.NotStacked, errors.UnstackableBranchFormat,
608
errors.UnstackableRepositoryFormat):
611
# repositories don't offer an interface to remove fallback
612
# repositories today; take the conceptually simpler option and just
614
self.repository = self.bzrdir.find_repository()
615
# for every revision reference the branch has, ensure it is pulled
617
source_repository = self._get_fallback_repository(old_url)
618
for revision_id in chain([self.last_revision()],
619
self.tags.get_reverse_tag_dict()):
620
self.repository.fetch(source_repository, revision_id,
623
self._activate_fallback_location(url)
624
# write this out after the repository is stacked to avoid setting a
625
# stacked config that doesn't work.
626
self._set_config_location('stacked_on_location', url)
574
629
def _set_tags_bytes(self, bytes):
575
630
"""Mirror method for _get_tags_bytes.
2161
2219
self._transport.put_bytes('parent', url + '\n',
2162
2220
mode=self.bzrdir._get_file_mode())
2164
def set_stacked_on_url(self, url):
2165
raise errors.UnstackableBranchFormat(self._format, self.base)
2168
2223
class BzrBranch5(BzrBranch):
2169
2224
"""A format 5 branch. This supports new features over plain branches.
2295
2350
class BzrBranch7(BzrBranch5):
2296
2351
"""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
2353
def _open_hook(self):
2311
2354
if self._ignore_fallbacks:
2325
2368
"None, not a URL." % hook_name)
2326
2369
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
2371
def __init__(self, *args, **kwargs):
2334
2372
self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2335
2373
super(BzrBranch7, self).__init__(*args, **kwargs)
2510
2548
self.get_config().set_user_option('append_revisions_only', value,
2511
2549
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
2551
def _get_append_revisions_only(self):
2540
2552
value = self.get_config().get_user_option('append_revisions_only')
2541
2553
return value == 'True'
2594
2606
def get_stacked_on_url(self):
2595
2607
raise errors.UnstackableBranchFormat(self._format, self.base)
2597
def set_stacked_on_url(self, url):
2598
raise errors.UnstackableBranchFormat(self._format, self.base)
2601
2610
######################################################################
2602
2611
# results of operations