~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-05-08 20:32:56 UTC
  • mfrom: (2483.1.2 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070508203256-wcxwdphd1y2psezh
(John Arbash Meinel) Merge fixes from 0.16 into bzr.dev and update for 0.17 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
997
997
        # (push_result)
998
998
        # containing the members
999
999
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1000
 
        # where local is the local branch or None, master is the target 
 
1000
        # where local is the local target branch or None, master is the target 
1001
1001
        # master branch, and the rest should be self explanatory. The source
1002
1002
        # is read locked and the target branches write locked. Source will
1003
1003
        # be the local low-latency branch.
1473
1473
 
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.
1478
1478
 
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.
1483
1484
        """
1484
1485
        result = PullResult()
1485
1486
        result.source_branch = source
1504
1505
            else:
1505
1506
                result.master_branch = self
1506
1507
                result.local_branch = None
1507
 
            if _run_hooks:
 
1508
            if run_hooks:
1508
1509
                for hook in Branch.hooks['post_pull']:
1509
1510
                    hook(result)
1510
1511
        finally:
1522
1523
 
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.
 
1528
 
 
1529
        This is the basic concrete implementation of push()
 
1530
 
 
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. 
 
1535
        """
 
1536
        # TODO: Public option to disable running hooks - should be trivial but
 
1537
        # needs tests.
 
1538
        target.lock_write()
 
1539
        try:
 
1540
            result = self._push_with_bound_branches(target, overwrite,
 
1541
                    stop_revision,
 
1542
                    _override_hook_source_branch=_override_hook_source_branch)
 
1543
            return result
 
1544
        finally:
 
1545
            target.unlock()
 
1546
 
 
1547
    def _push_with_bound_branches(self, target, overwrite,
 
1548
            stop_revision,
 
1549
            _override_hook_source_branch=None):
 
1550
        """Push from self into target, and into target's master if any.
1527
1551
        
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.
 
1554
        """
 
1555
        def _run_hooks():
 
1556
            if _override_hook_source_branch:
 
1557
                result.source_branch = _override_hook_source_branch
 
1558
            for hook in Branch.hooks['post_push']:
 
1559
                hook(result)
 
1560
 
 
1561
        bound_location = target.get_bound_location()
 
1562
        if bound_location and target.base != bound_location:
 
1563
            # there is a master branch.
 
1564
            #
 
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()
 
1569
            try:
 
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
 
1574
                # repository.
 
1575
                result = self._basic_push(target, overwrite, stop_revision)
 
1576
                result.master_branch = master_branch
 
1577
                result.local_branch = target
 
1578
                _run_hooks()
 
1579
                return result
 
1580
            finally:
 
1581
                master_branch.unlock()
 
1582
        else:
 
1583
            # no master branch
 
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
 
1587
            # 20070504
 
1588
            result.master_branch = target
 
1589
            result.local_branch = None
 
1590
            _run_hooks()
 
1591
            return result
 
1592
 
 
1593
    def _basic_push(self, target, overwrite, stop_revision):
 
1594
        """Basic implementation of push without bound branches or hooks.
 
1595
 
 
1596
        Must be called with self read locked and target write locked.
1532
1597
        """
1533
1598
        result = PushResult()
1534
1599
        result.source_branch = self
1535
1600
        result.target_branch = target
1536
 
        target.lock_write()
 
1601
        result.old_revno, result.old_revid = target.last_revision_info()
1537
1602
        try:
1538
 
            result.old_revno, result.old_revid = target.last_revision_info()
1539
 
            try:
1540
 
                target.update_revisions(self, stop_revision)
1541
 
            except DivergedBranches:
1542
 
                if not overwrite:
1543
 
                    raise
1544
 
            if overwrite:
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()
1548
 
            if _hook_master:
1549
 
                result.master_branch = _hook_master
1550
 
                result.local_branch = target
1551
 
            else:
1552
 
                result.master_branch = target
1553
 
                result.local_branch = None
1554
 
            if _run_hooks:
1555
 
                for hook in Branch.hooks['post_push']:
1556
 
                    hook(result)
1557
 
        finally:
1558
 
            target.unlock()
 
1603
            target.update_revisions(self, stop_revision)
 
1604
        except DivergedBranches:
 
1605
            if not overwrite:
 
1606
                raise
 
1607
        if overwrite:
 
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()
1559
1611
        return result
1560
1612
 
1561
1613
    def get_parent(self):
1631
1683
        
1632
1684
    @needs_write_lock
1633
1685
    def pull(self, source, overwrite=False, stop_revision=None,
1634
 
        _run_hooks=True):
1635
 
        """Extends branch.pull to be bound branch aware.
 
1686
             run_hooks=True):
 
1687
        """Pull from source into self, updating my master if any.
1636
1688
        
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.
1639
1692
        """
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,
1650
 
                    _run_hooks=False)
 
1703
                    run_hooks=False)
1651
1704
            return super(BzrBranch5, self).pull(source, overwrite,
1652
1705
                stop_revision, _hook_master=master_branch,
1653
 
                _run_hooks=_run_hooks)
1654
 
        finally:
1655
 
            if master_branch:
1656
 
                master_branch.unlock()
1657
 
 
1658
 
    @needs_read_lock
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()
1667
 
        try:
1668
 
            if master_branch:
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
1674
 
            # repository.
1675
 
            return super(BzrBranch5, self).push(target, overwrite,
1676
 
                stop_revision, _hook_master=master_branch)
 
1706
                run_hooks=run_hooks)
1677
1707
        finally:
1678
1708
            if master_branch:
1679
1709
                master_branch.unlock()