1474
1474
@needs_write_lock
1475
1475
def pull(self, source, overwrite=False, stop_revision=None,
1476
_hook_master=None, _run_hooks=True):
1476
_hook_master=None, run_hooks=True):
1477
1477
"""See Branch.pull.
1479
1479
:param _hook_master: Private parameter - set the branch to
1480
1480
be supplied as the master to push hooks.
1481
:param _run_hooks: Private parameter - allow disabling of
1482
hooks, used when pushing to a master branch.
1481
:param run_hooks: Private parameter - if false, this branch
1482
is being called because it's the master of the primary branch,
1483
so it should not run its hooks.
1484
1485
result = PullResult()
1485
1486
result.source_branch = source
1523
1524
@needs_read_lock
1524
1525
def push(self, target, overwrite=False, stop_revision=None,
1525
_hook_master=None, _run_hooks=True):
1526
_override_hook_source_branch=None):
1526
1527
"""See Branch.push.
1529
This is the basic concrete implementation of push()
1531
:param _override_hook_source_branch: If specified, run
1532
the hooks passing this Branch as the source, rather than self.
1533
This is for use of RemoteBranch, where push is delegated to the
1534
underlying vfs-based Branch.
1536
# TODO: Public option to disable running hooks - should be trivial but
1540
result = self._push_with_bound_branches(target, overwrite,
1542
_override_hook_source_branch=_override_hook_source_branch)
1547
def _push_with_bound_branches(self, target, overwrite,
1549
_override_hook_source_branch=None):
1550
"""Push from self into target, and into target's master if any.
1528
:param _hook_master: Private parameter - set the branch to
1529
be supplied as the master to push hooks.
1530
:param _run_hooks: Private parameter - allow disabling of
1531
hooks, used when pushing to a master branch.
1552
This is on the base BzrBranch class even though it doesn't support
1553
bound branches because the *target* might be bound.
1556
if _override_hook_source_branch:
1557
result.source_branch = _override_hook_source_branch
1558
for hook in Branch.hooks['post_push']:
1561
bound_location = target.get_bound_location()
1562
if bound_location and target.base != bound_location:
1563
# there is a master branch.
1565
# XXX: Why the second check? Is it even supported for a branch to
1566
# be bound to itself? -- mbp 20070507
1567
master_branch = target.get_master_branch()
1568
master_branch.lock_write()
1570
# push into the master from this branch.
1571
self._basic_push(master_branch, overwrite, stop_revision)
1572
# and push into the target branch from this. Note that we push from
1573
# this branch again, because its considered the highest bandwidth
1575
result = self._basic_push(target, overwrite, stop_revision)
1576
result.master_branch = master_branch
1577
result.local_branch = target
1581
master_branch.unlock()
1584
result = self._basic_push(target, overwrite, stop_revision)
1585
# TODO: Why set master_branch and local_branch if there's no
1586
# binding? Maybe cleaner to just leave them unset? -- mbp
1588
result.master_branch = target
1589
result.local_branch = None
1593
def _basic_push(self, target, overwrite, stop_revision):
1594
"""Basic implementation of push without bound branches or hooks.
1596
Must be called with self read locked and target write locked.
1533
1598
result = PushResult()
1534
1599
result.source_branch = self
1535
1600
result.target_branch = target
1601
result.old_revno, result.old_revid = target.last_revision_info()
1538
result.old_revno, result.old_revid = target.last_revision_info()
1540
target.update_revisions(self, stop_revision)
1541
except DivergedBranches:
1545
target.set_revision_history(self.revision_history())
1546
result.tag_conflicts = self.tags.merge_to(target.tags)
1547
result.new_revno, result.new_revid = target.last_revision_info()
1549
result.master_branch = _hook_master
1550
result.local_branch = target
1552
result.master_branch = target
1553
result.local_branch = None
1555
for hook in Branch.hooks['post_push']:
1603
target.update_revisions(self, stop_revision)
1604
except DivergedBranches:
1608
target.set_revision_history(self.revision_history())
1609
result.tag_conflicts = self.tags.merge_to(target.tags)
1610
result.new_revno, result.new_revid = target.last_revision_info()
1561
1613
def get_parent(self):
1632
1684
@needs_write_lock
1633
1685
def pull(self, source, overwrite=False, stop_revision=None,
1635
"""Extends branch.pull to be bound branch aware.
1687
"""Pull from source into self, updating my master if any.
1637
:param _run_hooks: Private parameter used to force hook running
1638
off during bound branch double-pushing.
1689
:param run_hooks: Private parameter - if false, this branch
1690
is being called because it's the master of the primary branch,
1691
so it should not run its hooks.
1640
1693
bound_location = self.get_bound_location()
1641
1694
master_branch = None
1647
1700
if master_branch:
1648
1701
# pull from source into master.
1649
1702
master_branch.pull(source, overwrite, stop_revision,
1651
1704
return super(BzrBranch5, self).pull(source, overwrite,
1652
1705
stop_revision, _hook_master=master_branch,
1653
_run_hooks=_run_hooks)
1656
master_branch.unlock()
1659
def push(self, target, overwrite=False, stop_revision=None):
1660
"""Updates branch.push to be bound branch aware."""
1661
bound_location = target.get_bound_location()
1662
master_branch = None
1663
if bound_location and target.base != bound_location:
1664
# not pushing to master, so we need to update master.
1665
master_branch = target.get_master_branch()
1666
master_branch.lock_write()
1669
# push into the master from this branch.
1670
super(BzrBranch5, self).push(master_branch, overwrite,
1671
stop_revision, _run_hooks=False)
1672
# and push into the target branch from this. Note that we push from
1673
# this branch again, because its considered the highest bandwidth
1675
return super(BzrBranch5, self).push(target, overwrite,
1676
stop_revision, _hook_master=master_branch)
1706
run_hooks=run_hooks)
1678
1708
if master_branch:
1679
1709
master_branch.unlock()