162
155
The default implementation returns False if this branch has no tags,
163
156
and True the rest of the time. Subclasses may override this.
165
return self.supports_tags() and self.tags.get_tag_dict()
158
return self.tags.supports_tags() and self.tags.get_tag_dict()
167
160
def get_config(self):
168
161
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
189
def _get_tags_bytes(self):
190
"""Get the bytes of a serialised tags dict.
192
Note that not all branches support tags, nor do all use the same tags
193
logic: this method is specific to BasicTags. Other tag implementations
194
may use the same method name and behave differently, safely, because
195
of the double-dispatch via
196
format.make_tags->tags_instance->get_tags_dict.
198
:return: The bytes of the tags file.
199
:seealso: Branch._set_tags_bytes.
201
return self._transport.get_bytes('tags')
203
163
def _get_nick(self, local=False, possible_transports=None):
204
164
config = self.get_config()
205
165
# explicit overrides master, but don't look for master if local is True
598
563
:raises UnstackableRepositoryFormat: If the repository does not support
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)
629
def _set_tags_bytes(self, bytes):
630
"""Mirror method for _get_tags_bytes.
632
:seealso: Branch._get_tags_bytes.
634
return _run_with_write_locked_target(self, self._transport.put_bytes,
566
raise NotImplementedError(self.set_stacked_on_url)
637
568
def _cache_revision_history(self, rev_history):
638
569
"""Set the cached revision history to rev_history.
1428
1342
Hooks.__init__(self)
1429
self.create_hook(HookPoint('set_rh',
1430
"Invoked whenever the revision history has been set via "
1431
"set_revision_history. The api signature is (branch, "
1432
"revision_history), and the branch will be write-locked. "
1433
"The set_rh hook can be expensive for bzr to trigger, a better "
1434
"hook to use is Branch.post_change_branch_tip.", (0, 15), None))
1435
self.create_hook(HookPoint('open',
1436
"Called with the Branch object that has been opened after a "
1437
"branch is opened.", (1, 8), None))
1438
self.create_hook(HookPoint('post_push',
1439
"Called after a push operation completes. post_push is called "
1440
"with a bzrlib.branch.BranchPushResult object and only runs in the "
1441
"bzr client.", (0, 15), None))
1442
self.create_hook(HookPoint('post_pull',
1443
"Called after a pull operation completes. post_pull is called "
1444
"with a bzrlib.branch.PullResult object and only runs in the "
1445
"bzr client.", (0, 15), None))
1446
self.create_hook(HookPoint('pre_commit',
1447
"Called after a commit is calculated but before it is is "
1448
"completed. pre_commit is called with (local, master, old_revno, "
1449
"old_revid, future_revno, future_revid, tree_delta, future_tree"
1450
"). old_revid is NULL_REVISION for the first commit to a branch, "
1451
"tree_delta is a TreeDelta object describing changes from the "
1452
"basis revision. hooks MUST NOT modify this delta. "
1453
" future_tree is an in-memory tree obtained from "
1454
"CommitBuilder.revision_tree() and hooks MUST NOT modify this "
1455
"tree.", (0,91), None))
1456
self.create_hook(HookPoint('post_commit',
1457
"Called in the bzr client after a commit has completed. "
1458
"post_commit is called with (local, master, old_revno, old_revid, "
1459
"new_revno, new_revid). old_revid is NULL_REVISION for the first "
1460
"commit to a branch.", (0, 15), None))
1461
self.create_hook(HookPoint('post_uncommit',
1462
"Called in the bzr client after an uncommit completes. "
1463
"post_uncommit is called with (local, master, old_revno, "
1464
"old_revid, new_revno, new_revid) where local is the local branch "
1465
"or None, master is the target branch, and an empty branch "
1466
"receives new_revno of 0, new_revid of None.", (0, 15), None))
1467
self.create_hook(HookPoint('pre_change_branch_tip',
1468
"Called in bzr client and server before a change to the tip of a "
1469
"branch is made. pre_change_branch_tip is called with a "
1470
"bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
1471
"commit, uncommit will all trigger this hook.", (1, 6), None))
1472
self.create_hook(HookPoint('post_change_branch_tip',
1473
"Called in bzr client and server after a change to the tip of a "
1474
"branch is made. post_change_branch_tip is called with a "
1475
"bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
1476
"commit, uncommit will all trigger this hook.", (1, 4), None))
1477
self.create_hook(HookPoint('transform_fallback_location',
1478
"Called when a stacked branch is activating its fallback "
1479
"locations. transform_fallback_location is called with (branch, "
1480
"url), and should return a new url. Returning the same url "
1481
"allows it to be used as-is, returning a different one can be "
1482
"used to cause the branch to stack on a closer copy of that "
1483
"fallback_location. Note that the branch cannot have history "
1484
"accessing methods called on it during this hook because the "
1485
"fallback locations have not been activated. When there are "
1486
"multiple hooks installed for transform_fallback_location, "
1487
"all are called with the url returned from the previous hook."
1488
"The order is however undefined.", (1, 9), None))
1343
# Introduced in 0.15:
1344
# invoked whenever the revision history has been set
1345
# with set_revision_history. The api signature is
1346
# (branch, revision_history), and the branch will
1349
# Invoked after a branch is opened. The api signature is (branch).
1351
# invoked after a push operation completes.
1352
# the api signature is
1354
# containing the members
1355
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
1356
# where local is the local target branch or None, master is the target
1357
# master branch, and the rest should be self explanatory. The source
1358
# is read locked and the target branches write locked. Source will
1359
# be the local low-latency branch.
1360
self['post_push'] = []
1361
# invoked after a pull operation completes.
1362
# the api signature is
1364
# containing the members
1365
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
1366
# where local is the local branch or None, master is the target
1367
# master branch, and the rest should be self explanatory. The source
1368
# is read locked and the target branches write locked. The local
1369
# branch is the low-latency branch.
1370
self['post_pull'] = []
1371
# invoked before a commit operation takes place.
1372
# the api signature is
1373
# (local, master, old_revno, old_revid, future_revno, future_revid,
1374
# tree_delta, future_tree).
1375
# old_revid is NULL_REVISION for the first commit to a branch
1376
# tree_delta is a TreeDelta object describing changes from the basis
1377
# revision, hooks MUST NOT modify this delta
1378
# future_tree is an in-memory tree obtained from
1379
# CommitBuilder.revision_tree() and hooks MUST NOT modify this tree
1380
self['pre_commit'] = []
1381
# invoked after a commit operation completes.
1382
# the api signature is
1383
# (local, master, old_revno, old_revid, new_revno, new_revid)
1384
# old_revid is NULL_REVISION for the first commit to a branch.
1385
self['post_commit'] = []
1386
# invoked after a uncommit operation completes.
1387
# the api signature is
1388
# (local, master, old_revno, old_revid, new_revno, new_revid) where
1389
# local is the local branch or None, master is the target branch,
1390
# and an empty branch recieves new_revno of 0, new_revid of None.
1391
self['post_uncommit'] = []
1393
# Invoked before the tip of a branch changes.
1394
# the api signature is
1395
# (params) where params is a ChangeBranchTipParams with the members
1396
# (branch, old_revno, new_revno, old_revid, new_revid)
1397
self['pre_change_branch_tip'] = []
1399
# Invoked after the tip of a branch changes.
1400
# the api signature is
1401
# (params) where params is a ChangeBranchTipParams with the members
1402
# (branch, old_revno, new_revno, old_revid, new_revid)
1403
self['post_change_branch_tip'] = []
1405
# Invoked when a stacked branch activates its fallback locations and
1406
# allows the transformation of the url of said location.
1407
# the api signature is
1408
# (branch, url) where branch is the branch having its fallback
1409
# location activated and url is the url for the fallback location.
1410
# The hook should return a url.
1411
self['transform_fallback_location'] = []
1491
1414
# install the default hooks into the Branch class.