/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

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        bzrdir,
27
27
        cache_utf8,
28
28
        config as _mod_config,
 
29
        debug,
29
30
        errors,
30
31
        lockdir,
31
32
        lockable_files,
61
62
                                      zero_eight, zero_nine, zero_sixteen,
62
63
                                      zero_ninetyone,
63
64
                                      )
64
 
from bzrlib.trace import mutter, note
 
65
from bzrlib.trace import mutter, mutter_callsite, note
65
66
 
66
67
 
67
68
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
117
118
            master.break_lock()
118
119
 
119
120
    @staticmethod
120
 
    def open(base, _unsupported=False):
 
121
    def open(base, _unsupported=False, possible_transports=None):
121
122
        """Open the branch rooted at base.
122
123
 
123
124
        For instance, if the branch is at URL/.bzr/branch,
124
125
        Branch.open(URL) -> a Branch instance.
125
126
        """
126
 
        control = bzrdir.BzrDir.open(base, _unsupported)
 
127
        control = bzrdir.BzrDir.open(base, _unsupported,
 
128
                                     possible_transports=possible_transports)
127
129
        return control.open_branch(_unsupported)
128
130
 
129
131
    @staticmethod
320
322
        return self.repository.get_commit_builder(self, parents, config,
321
323
            timestamp, timezone, committer, revprops, revision_id)
322
324
 
323
 
    def get_master_branch(self):
 
325
    def get_master_branch(self, possible_transports=None):
324
326
        """Return the branch we are bound to.
325
327
        
326
328
        :return: Either a Branch, or None
403
405
 
404
406
    @needs_read_lock
405
407
    def revision_history(self):
406
 
        """Return sequence of revision hashes on to this branch.
 
408
        """Return sequence of revision ids on this branch.
407
409
        
408
410
        This method will cache the revision history for as long as it is safe to
409
411
        do so.
410
412
        """
 
413
        if 'evil' in debug.debug_flags:
 
414
            mutter_callsite(3, "revision_history scales with history.")
411
415
        if self._revision_history_cache is not None:
412
416
            history = self._revision_history_cache
413
417
        else:
487
491
        """Given a revision id, return its revno"""
488
492
        if _mod_revision.is_null(revision_id):
489
493
            return 0
490
 
        revision_id = osutils.safe_revision_id(revision_id)
491
494
        history = self.revision_history()
492
495
        try:
493
496
            return history.index(revision_id) + 1
504
507
            raise errors.NoSuchRevision(self, revno)
505
508
        return history[revno - 1]
506
509
 
507
 
    def pull(self, source, overwrite=False, stop_revision=None):
 
510
    def pull(self, source, overwrite=False, stop_revision=None,
 
511
             possible_transports=None):
508
512
        """Mirror source into this branch.
509
513
 
510
514
        This branch is considered to be 'local', having low latency.
685
689
            new_history = []
686
690
        new_history = self.revision_history()
687
691
        if revision_id is not None and new_history != []:
688
 
            revision_id = osutils.safe_revision_id(revision_id)
689
692
            try:
690
693
                new_history = new_history[:new_history.index(revision_id) + 1]
691
694
            except ValueError:
1362
1365
    @needs_write_lock
1363
1366
    def set_revision_history(self, rev_history):
1364
1367
        """See Branch.set_revision_history."""
1365
 
        rev_history = [osutils.safe_revision_id(r) for r in rev_history]
 
1368
        if 'evil' in debug.debug_flags:
 
1369
            mutter_callsite(3, "set_revision_history scales with history.")
1366
1370
        self._clear_cached_state()
1367
1371
        self._write_revision_history(rev_history)
1368
1372
        self._cache_revision_history(rev_history)
1381
1385
        configured to check constraints on history, in which case this may not
1382
1386
        be permitted.
1383
1387
        """
1384
 
        revision_id = osutils.safe_revision_id(revision_id)
1385
1388
        history = self._lefthand_history(revision_id)
1386
1389
        assert len(history) == revno, '%d != %d' % (len(history), revno)
1387
1390
        self.set_revision_history(history)
1395
1398
 
1396
1399
    def _lefthand_history(self, revision_id, last_rev=None,
1397
1400
                          other_branch=None):
 
1401
        if 'evil' in debug.debug_flags:
 
1402
            mutter_callsite(4, "_lefthand_history scales with history.")
1398
1403
        # stop_revision must be a descendant of last_revision
1399
1404
        stop_graph = self.repository.get_revision_graph(revision_id)
1400
1405
        if (last_rev is not None and last_rev != _mod_revision.NULL_REVISION
1425
1430
        :param other_branch: The other branch that DivergedBranches should
1426
1431
            raise with respect to.
1427
1432
        """
1428
 
        revision_id = osutils.safe_revision_id(revision_id)
1429
1433
        self.set_revision_history(self._lefthand_history(revision_id,
1430
1434
            last_rev, other_branch))
1431
1435
 
1439
1443
                if stop_revision is None:
1440
1444
                    # if there are no commits, we're done.
1441
1445
                    return
1442
 
            else:
1443
 
                stop_revision = osutils.safe_revision_id(stop_revision)
1444
1446
            # whats the current last revision, before we fetch [and change it
1445
1447
            # possibly]
1446
1448
            last_rev = _mod_revision.ensure_null(self.last_revision())
1447
 
            # we fetch here regardless of whether we need to so that we pickup
1448
 
            # filled in ghosts.
 
1449
            # we fetch here so that we don't process data twice in the common
 
1450
            # case of having something to pull, and so that the check for 
 
1451
            # already merged can operate on the just fetched graph, which will
 
1452
            # be cached in memory.
1449
1453
            self.fetch(other, stop_revision)
1450
1454
            if self.repository.get_graph().is_ancestor(stop_revision,
1451
1455
                                                       last_rev):
1461
1465
 
1462
1466
    @needs_write_lock
1463
1467
    def pull(self, source, overwrite=False, stop_revision=None,
1464
 
             _hook_master=None, run_hooks=True):
 
1468
             _hook_master=None, run_hooks=True, possible_transports=None):
1465
1469
        """See Branch.pull.
1466
1470
 
1467
1471
        :param _hook_master: Private parameter - set the branch to 
1485
1489
                if stop_revision is None:
1486
1490
                    stop_revision = source.last_revision()
1487
1491
                self.generate_revision_history(stop_revision)
1488
 
            result.tag_conflicts = source.tags.merge_to(self.tags)
 
1492
            result.tag_conflicts = source.tags.merge_to(self.tags, overwrite)
1489
1493
            result.new_revno, result.new_revid = self.last_revision_info()
1490
1494
            if _hook_master:
1491
1495
                result.master_branch = _hook_master
1594
1598
                raise
1595
1599
        if overwrite:
1596
1600
            target.set_revision_history(self.revision_history())
1597
 
        result.tag_conflicts = self.tags.merge_to(target.tags)
 
1601
        result.tag_conflicts = self.tags.merge_to(target.tags, overwrite)
1598
1602
        result.new_revno, result.new_revid = target.last_revision_info()
1599
1603
        return result
1600
1604
 
1648
1652
 
1649
1653
 
1650
1654
class BzrBranch5(BzrBranch):
1651
 
    """A format 5 branch. This supports new features over plan branches.
 
1655
    """A format 5 branch. This supports new features over plain branches.
1652
1656
 
1653
1657
    It has support for a master_branch which is the data for bound branches.
1654
1658
    """
1665
1669
        
1666
1670
    @needs_write_lock
1667
1671
    def pull(self, source, overwrite=False, stop_revision=None,
1668
 
             run_hooks=True):
 
1672
             run_hooks=True, possible_transports=None):
1669
1673
        """Pull from source into self, updating my master if any.
1670
1674
        
1671
1675
        :param run_hooks: Private parameter - if false, this branch
1676
1680
        master_branch = None
1677
1681
        if bound_location and source.base != bound_location:
1678
1682
            # not pulling from master, so we need to update master.
1679
 
            master_branch = self.get_master_branch()
 
1683
            master_branch = self.get_master_branch(possible_transports)
1680
1684
            master_branch.lock_write()
1681
1685
        try:
1682
1686
            if master_branch:
1697
1701
            return None
1698
1702
 
1699
1703
    @needs_read_lock
1700
 
    def get_master_branch(self):
 
1704
    def get_master_branch(self, possible_transports=None):
1701
1705
        """Return the branch we are bound to.
1702
1706
        
1703
1707
        :return: Either a Branch, or None
1711
1715
        if not bound_loc:
1712
1716
            return None
1713
1717
        try:
1714
 
            return Branch.open(bound_loc)
 
1718
            return Branch.open(bound_loc,
 
1719
                               possible_transports=possible_transports)
1715
1720
        except (errors.NotBranchError, errors.ConnectionError), e:
1716
1721
            raise errors.BoundBranchConnectionFailure(
1717
1722
                    self, bound_loc, e)
1779
1784
        return self.set_bound_location(None)
1780
1785
 
1781
1786
    @needs_write_lock
1782
 
    def update(self):
 
1787
    def update(self, possible_transports=None):
1783
1788
        """Synchronise this branch with the master branch if any. 
1784
1789
 
1785
1790
        :return: None or the last_revision that was pivoted out during the
1786
1791
                 update.
1787
1792
        """
1788
 
        master = self.get_master_branch()
 
1793
        master = self.get_master_branch(possible_transports)
1789
1794
        if master is not None:
1790
1795
            old_tip = _mod_revision.ensure_null(self.last_revision())
1791
1796
            self.pull(master, overwrite=True)
1928
1933
 
1929
1934
    @needs_write_lock
1930
1935
    def set_last_revision_info(self, revno, revision_id):
1931
 
        revision_id = osutils.safe_revision_id(revision_id)
1932
1936
        if self._get_append_revisions_only():
1933
1937
            self._check_history_violation(revision_id)
1934
1938
        self._write_last_revision_info(revno, revision_id)