~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Aaron Bentley
  • Date: 2007-05-14 17:21:02 UTC
  • mfrom: (2485 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2528.
  • Revision ID: aaron.bentley@utoronto.ca-20070514172102-byyl4ldjxhfxvryy
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
783
783
        :return: The tree of the created checkout
784
784
        """
785
785
        t = transport.get_transport(to_location)
786
 
        try:
787
 
            t.mkdir('.')
788
 
        except errors.FileExists:
789
 
            pass
 
786
        t.ensure_base()
790
787
        if lightweight:
791
788
            format = self._get_checkout_format()
792
789
            checkout = format.initialize_on_transport(t)
1006
1003
        # (push_result)
1007
1004
        # containing the members
1008
1005
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1009
 
        # where local is the local branch or None, master is the target 
 
1006
        # where local is the local target branch or None, master is the target 
1010
1007
        # master branch, and the rest should be self explanatory. The source
1011
1008
        # is read locked and the target branches write locked. Source will
1012
1009
        # be the local low-latency branch.
1482
1479
 
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.
1487
1484
 
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.
1492
1490
        """
1493
1491
        result = PullResult()
1494
1492
        result.source_branch = source
1513
1511
            else:
1514
1512
                result.master_branch = self
1515
1513
                result.local_branch = None
1516
 
            if _run_hooks:
 
1514
            if run_hooks:
1517
1515
                for hook in Branch.hooks['post_pull']:
1518
1516
                    hook(result)
1519
1517
        finally:
1531
1529
 
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.
 
1534
 
 
1535
        This is the basic concrete implementation of push()
 
1536
 
 
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. 
 
1541
        """
 
1542
        # TODO: Public option to disable running hooks - should be trivial but
 
1543
        # needs tests.
 
1544
        target.lock_write()
 
1545
        try:
 
1546
            result = self._push_with_bound_branches(target, overwrite,
 
1547
                    stop_revision,
 
1548
                    _override_hook_source_branch=_override_hook_source_branch)
 
1549
            return result
 
1550
        finally:
 
1551
            target.unlock()
 
1552
 
 
1553
    def _push_with_bound_branches(self, target, overwrite,
 
1554
            stop_revision,
 
1555
            _override_hook_source_branch=None):
 
1556
        """Push from self into target, and into target's master if any.
1536
1557
        
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.
 
1560
        """
 
1561
        def _run_hooks():
 
1562
            if _override_hook_source_branch:
 
1563
                result.source_branch = _override_hook_source_branch
 
1564
            for hook in Branch.hooks['post_push']:
 
1565
                hook(result)
 
1566
 
 
1567
        bound_location = target.get_bound_location()
 
1568
        if bound_location and target.base != bound_location:
 
1569
            # there is a master branch.
 
1570
            #
 
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()
 
1575
            try:
 
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
 
1580
                # repository.
 
1581
                result = self._basic_push(target, overwrite, stop_revision)
 
1582
                result.master_branch = master_branch
 
1583
                result.local_branch = target
 
1584
                _run_hooks()
 
1585
                return result
 
1586
            finally:
 
1587
                master_branch.unlock()
 
1588
        else:
 
1589
            # no master branch
 
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
 
1593
            # 20070504
 
1594
            result.master_branch = target
 
1595
            result.local_branch = None
 
1596
            _run_hooks()
 
1597
            return result
 
1598
 
 
1599
    def _basic_push(self, target, overwrite, stop_revision):
 
1600
        """Basic implementation of push without bound branches or hooks.
 
1601
 
 
1602
        Must be called with self read locked and target write locked.
1541
1603
        """
1542
1604
        result = PushResult()
1543
1605
        result.source_branch = self
1544
1606
        result.target_branch = target
1545
 
        target.lock_write()
 
1607
        result.old_revno, result.old_revid = target.last_revision_info()
1546
1608
        try:
1547
 
            result.old_revno, result.old_revid = target.last_revision_info()
1548
 
            try:
1549
 
                target.update_revisions(self, stop_revision)
1550
 
            except DivergedBranches:
1551
 
                if not overwrite:
1552
 
                    raise
1553
 
            if overwrite:
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()
1557
 
            if _hook_master:
1558
 
                result.master_branch = _hook_master
1559
 
                result.local_branch = target
1560
 
            else:
1561
 
                result.master_branch = target
1562
 
                result.local_branch = None
1563
 
            if _run_hooks:
1564
 
                for hook in Branch.hooks['post_push']:
1565
 
                    hook(result)
1566
 
        finally:
1567
 
            target.unlock()
 
1609
            target.update_revisions(self, stop_revision)
 
1610
        except DivergedBranches:
 
1611
            if not overwrite:
 
1612
                raise
 
1613
        if overwrite:
 
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()
1568
1617
        return result
1569
1618
 
1570
1619
    def get_parent(self):
1640
1689
        
1641
1690
    @needs_write_lock
1642
1691
    def pull(self, source, overwrite=False, stop_revision=None,
1643
 
        _run_hooks=True):
1644
 
        """Extends branch.pull to be bound branch aware.
 
1692
             run_hooks=True):
 
1693
        """Pull from source into self, updating my master if any.
1645
1694
        
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.
1648
1698
        """
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,
1659
 
                    _run_hooks=False)
 
1709
                    run_hooks=False)
1660
1710
            return super(BzrBranch5, self).pull(source, overwrite,
1661
1711
                stop_revision, _hook_master=master_branch,
1662
 
                _run_hooks=_run_hooks)
1663
 
        finally:
1664
 
            if master_branch:
1665
 
                master_branch.unlock()
1666
 
 
1667
 
    @needs_read_lock
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()
1676
 
        try:
1677
 
            if master_branch:
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
1683
 
            # repository.
1684
 
            return super(BzrBranch5, self).push(target, overwrite,
1685
 
                stop_revision, _hook_master=master_branch)
 
1712
                run_hooks=run_hooks)
1686
1713
        finally:
1687
1714
            if master_branch:
1688
1715
                master_branch.unlock()