/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2007-05-04 08:46:39 UTC
  • mto: (2483.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2484.
  • Revision ID: mbp@sourcefrog.net-20070504084639-8v8mzetmr1y74xer
Rename push/pull back to 'run_hooks' (jameinel)

Reorganize Branch.push into some template methods: public push,
_push_with_bound_branches, and _basic_push.  This fixes the case 
where the destination of push is bound, but the source branch
format doesn't support binding.

Run push and pull hook tests with a local branch that does support binding,
rather than skipping if the branch can't be bound to another of the same
format.

(broken) because the hooks are given the wrong parameters when 
pushing into something bound to a remote branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1000
1000
        # (push_result)
1001
1001
        # containing the members
1002
1002
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1003
 
        # where local is the local branch or None, master is the target 
 
1003
        # where local is the local target branch or None, master is the target 
1004
1004
        # master branch, and the rest should be self explanatory. The source
1005
1005
        # is read locked and the target branches write locked. Source will
1006
1006
        # be the local low-latency branch.
1476
1476
 
1477
1477
    @needs_write_lock
1478
1478
    def pull(self, source, overwrite=False, stop_revision=None,
1479
 
        _hook_master=None, _run_hooks=True):
 
1479
        _hook_master=None, run_hooks=True):
1480
1480
        """See Branch.pull.
1481
1481
 
1482
1482
        :param _hook_master: Private parameter - set the branch to 
1483
1483
            be supplied as the master to push hooks.
1484
 
        :param _run_hooks: Private parameter - allow disabling of
1485
 
            hooks, used when pushing to a master branch.
 
1484
        :param run_hooks: Private parameter - if false, this branch
 
1485
            is being called because it's the master of the primary branch,
 
1486
            so it should not run its hooks.
1486
1487
        """
1487
1488
        result = PullResult()
1488
1489
        result.source_branch = source
1507
1508
            else:
1508
1509
                result.master_branch = self
1509
1510
                result.local_branch = None
1510
 
            if _run_hooks:
 
1511
            if run_hooks:
1511
1512
                for hook in Branch.hooks['post_pull']:
1512
1513
                    hook(result)
1513
1514
        finally:
1525
1526
 
1526
1527
    @needs_read_lock
1527
1528
    def push(self, target, overwrite=False, stop_revision=None,
1528
 
        _hook_master=None, _run_hooks=True):
 
1529
        _hook_master=None, run_hooks=True):
1529
1530
        """See Branch.push.
 
1531
 
 
1532
        This is the basic concrete implementation of push()
1530
1533
        
1531
1534
        :param _hook_master: Private parameter - set the branch to 
1532
1535
            be supplied as the master to push hooks.
1533
 
        :param _run_hooks: Private parameter - allow disabling of
1534
 
            hooks, used when pushing to a master branch.
1535
 
        """
 
1536
        :param run_hooks: Private parameter - if false, this branch
 
1537
            is being called because it's the master of the primary branch,
 
1538
            so it should not run its hooks.
 
1539
        """
 
1540
        return self._push_with_bound_branches(target, overwrite,
 
1541
                stop_revision, _hook_master, run_hooks)
 
1542
 
 
1543
    def _push_with_bound_branches(self, target, overwrite,
 
1544
            stop_revision, _hook_master, run_hooks):
 
1545
        """Updates branch.push to be bound branch aware
 
1546
        
 
1547
        This is on the base BzrBranch class even though it doesn't support 
 
1548
        bound branches because the *target* might be bound.
 
1549
        """
 
1550
        bound_location = target.get_bound_location()
 
1551
        master_branch = None
 
1552
        if bound_location and target.base != bound_location:
 
1553
            # not pushing to master, so we need to update master.
 
1554
            master_branch = target.get_master_branch()
 
1555
            master_branch.lock_write()
 
1556
        try:
 
1557
            if master_branch:
 
1558
                # push into the master from this branch.
 
1559
                self._basic_push(master_branch, overwrite, stop_revision,
 
1560
                    stop_revision, run_hooks=False)
 
1561
            # and push into the target branch from this. Note that we push from
 
1562
            # this branch again, because its considered the highest bandwidth
 
1563
            # repository.
 
1564
            return self._basic_push(target, overwrite, stop_revision,
 
1565
                    _hook_master=master_branch, run_hooks=run_hooks)
 
1566
        finally:
 
1567
            if master_branch:
 
1568
                master_branch.unlock()
 
1569
 
 
1570
    def _basic_push(self, target, overwrite, stop_revision, _hook_master,
 
1571
            run_hooks):
 
1572
        """Basic implementation of push without considering bound branches."""
1536
1573
        result = PushResult()
1537
1574
        result.source_branch = self
1538
1575
        result.target_branch = target
1554
1591
            else:
1555
1592
                result.master_branch = target
1556
1593
                result.local_branch = None
1557
 
            if _run_hooks:
 
1594
            if run_hooks:
1558
1595
                for hook in Branch.hooks['post_push']:
1559
1596
                    hook(result)
1560
1597
        finally:
1634
1671
        
1635
1672
    @needs_write_lock
1636
1673
    def pull(self, source, overwrite=False, stop_revision=None,
1637
 
        _run_hooks=True):
 
1674
        run_hooks=True):
1638
1675
        """Extends branch.pull to be bound branch aware.
1639
1676
        
1640
 
        :param _run_hooks: Private parameter used to force hook running
1641
 
            off during bound branch double-pushing.
 
1677
        :param run_hooks: Private parameter - if false, this branch
 
1678
            is being called because it's the master of the primary branch,
 
1679
            so it should not run its hooks.
1642
1680
        """
1643
1681
        bound_location = self.get_bound_location()
1644
1682
        master_branch = None
1650
1688
            if master_branch:
1651
1689
                # pull from source into master.
1652
1690
                master_branch.pull(source, overwrite, stop_revision,
1653
 
                    _run_hooks=False)
 
1691
                    run_hooks=False)
1654
1692
            return super(BzrBranch5, self).pull(source, overwrite,
1655
1693
                stop_revision, _hook_master=master_branch,
1656
 
                _run_hooks=_run_hooks)
1657
 
        finally:
1658
 
            if master_branch:
1659
 
                master_branch.unlock()
1660
 
 
1661
 
    @needs_read_lock
1662
 
    def push(self, target, overwrite=False, stop_revision=None):
1663
 
        """Updates branch.push to be bound branch aware."""
1664
 
        bound_location = target.get_bound_location()
1665
 
        master_branch = None
1666
 
        if bound_location and target.base != bound_location:
1667
 
            # not pushing to master, so we need to update master.
1668
 
            master_branch = target.get_master_branch()
1669
 
            master_branch.lock_write()
1670
 
        try:
1671
 
            if master_branch:
1672
 
                # push into the master from this branch.
1673
 
                super(BzrBranch5, self).push(master_branch, overwrite,
1674
 
                    stop_revision, _run_hooks=False)
1675
 
            # and push into the target branch from this. Note that we push from
1676
 
            # this branch again, because its considered the highest bandwidth
1677
 
            # repository.
1678
 
            return super(BzrBranch5, self).push(target, overwrite,
1679
 
                stop_revision, _hook_master=master_branch)
 
1694
                run_hooks=run_hooks)
1680
1695
        finally:
1681
1696
            if master_branch:
1682
1697
                master_branch.unlock()