1483
1480
@needs_write_lock
1484
1481
def pull(self, source, overwrite=False, stop_revision=None,
1485
_hook_master=None, _run_hooks=True):
1482
_hook_master=None, run_hooks=True):
1486
1483
"""See Branch.pull.
1488
1485
:param _hook_master: Private parameter - set the branch to
1489
1486
be supplied as the master to push hooks.
1490
:param _run_hooks: Private parameter - allow disabling of
1491
hooks, used when pushing to a master branch.
1487
:param run_hooks: Private parameter - if false, this branch
1488
is being called because it's the master of the primary branch,
1489
so it should not run its hooks.
1493
1491
result = PullResult()
1494
1492
result.source_branch = source
1532
1530
@needs_read_lock
1533
1531
def push(self, target, overwrite=False, stop_revision=None,
1534
_hook_master=None, _run_hooks=True):
1532
_override_hook_source_branch=None):
1535
1533
"""See Branch.push.
1535
This is the basic concrete implementation of push()
1537
:param _override_hook_source_branch: If specified, run
1538
the hooks passing this Branch as the source, rather than self.
1539
This is for use of RemoteBranch, where push is delegated to the
1540
underlying vfs-based Branch.
1542
# TODO: Public option to disable running hooks - should be trivial but
1546
result = self._push_with_bound_branches(target, overwrite,
1548
_override_hook_source_branch=_override_hook_source_branch)
1553
def _push_with_bound_branches(self, target, overwrite,
1555
_override_hook_source_branch=None):
1556
"""Push from self into target, and into target's master if any.
1537
:param _hook_master: Private parameter - set the branch to
1538
be supplied as the master to push hooks.
1539
:param _run_hooks: Private parameter - allow disabling of
1540
hooks, used when pushing to a master branch.
1558
This is on the base BzrBranch class even though it doesn't support
1559
bound branches because the *target* might be bound.
1562
if _override_hook_source_branch:
1563
result.source_branch = _override_hook_source_branch
1564
for hook in Branch.hooks['post_push']:
1567
bound_location = target.get_bound_location()
1568
if bound_location and target.base != bound_location:
1569
# there is a master branch.
1571
# XXX: Why the second check? Is it even supported for a branch to
1572
# be bound to itself? -- mbp 20070507
1573
master_branch = target.get_master_branch()
1574
master_branch.lock_write()
1576
# push into the master from this branch.
1577
self._basic_push(master_branch, overwrite, stop_revision)
1578
# and push into the target branch from this. Note that we push from
1579
# this branch again, because its considered the highest bandwidth
1581
result = self._basic_push(target, overwrite, stop_revision)
1582
result.master_branch = master_branch
1583
result.local_branch = target
1587
master_branch.unlock()
1590
result = self._basic_push(target, overwrite, stop_revision)
1591
# TODO: Why set master_branch and local_branch if there's no
1592
# binding? Maybe cleaner to just leave them unset? -- mbp
1594
result.master_branch = target
1595
result.local_branch = None
1599
def _basic_push(self, target, overwrite, stop_revision):
1600
"""Basic implementation of push without bound branches or hooks.
1602
Must be called with self read locked and target write locked.
1542
1604
result = PushResult()
1543
1605
result.source_branch = self
1544
1606
result.target_branch = target
1607
result.old_revno, result.old_revid = target.last_revision_info()
1547
result.old_revno, result.old_revid = target.last_revision_info()
1549
target.update_revisions(self, stop_revision)
1550
except DivergedBranches:
1554
target.set_revision_history(self.revision_history())
1555
result.tag_conflicts = self.tags.merge_to(target.tags)
1556
result.new_revno, result.new_revid = target.last_revision_info()
1558
result.master_branch = _hook_master
1559
result.local_branch = target
1561
result.master_branch = target
1562
result.local_branch = None
1564
for hook in Branch.hooks['post_push']:
1609
target.update_revisions(self, stop_revision)
1610
except DivergedBranches:
1614
target.set_revision_history(self.revision_history())
1615
result.tag_conflicts = self.tags.merge_to(target.tags)
1616
result.new_revno, result.new_revid = target.last_revision_info()
1570
1619
def get_parent(self):
1641
1690
@needs_write_lock
1642
1691
def pull(self, source, overwrite=False, stop_revision=None,
1644
"""Extends branch.pull to be bound branch aware.
1693
"""Pull from source into self, updating my master if any.
1646
:param _run_hooks: Private parameter used to force hook running
1647
off during bound branch double-pushing.
1695
:param run_hooks: Private parameter - if false, this branch
1696
is being called because it's the master of the primary branch,
1697
so it should not run its hooks.
1649
1699
bound_location = self.get_bound_location()
1650
1700
master_branch = None
1656
1706
if master_branch:
1657
1707
# pull from source into master.
1658
1708
master_branch.pull(source, overwrite, stop_revision,
1660
1710
return super(BzrBranch5, self).pull(source, overwrite,
1661
1711
stop_revision, _hook_master=master_branch,
1662
_run_hooks=_run_hooks)
1665
master_branch.unlock()
1668
def push(self, target, overwrite=False, stop_revision=None):
1669
"""Updates branch.push to be bound branch aware."""
1670
bound_location = target.get_bound_location()
1671
master_branch = None
1672
if bound_location and target.base != bound_location:
1673
# not pushing to master, so we need to update master.
1674
master_branch = target.get_master_branch()
1675
master_branch.lock_write()
1678
# push into the master from this branch.
1679
super(BzrBranch5, self).push(master_branch, overwrite,
1680
stop_revision, _run_hooks=False)
1681
# and push into the target branch from this. Note that we push from
1682
# this branch again, because its considered the highest bandwidth
1684
return super(BzrBranch5, self).push(target, overwrite,
1685
stop_revision, _hook_master=master_branch)
1712
run_hooks=run_hooks)
1687
1714
if master_branch:
1688
1715
master_branch.unlock()