~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Merge thread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
        self.tags = self._make_tags()
86
86
        self._revision_history_cache = None
87
87
        self._revision_id_to_revno_cache = None
 
88
        self._last_revision_info_cache = None
88
89
 
89
90
    def break_lock(self):
90
91
        """Break a lock if one is present from another instance.
361
362
        """
362
363
        self._revision_history_cache = None
363
364
        self._revision_id_to_revno_cache = None
 
365
        self._last_revision_info_cache = None
364
366
 
365
367
    def _gen_revision_history(self):
366
368
        """Return sequence of revision hashes on to this branch.
413
415
        """Return last revision id, or NULL_REVISION."""
414
416
        return self.last_revision_info()[1]
415
417
 
 
418
    @needs_read_lock
416
419
    def last_revision_info(self):
417
420
        """Return information about the last revision.
418
421
 
419
 
        :return: A tuple (revno, last_revision_id).
 
422
        :return: A tuple (revno, revision_id).
420
423
        """
 
424
        if self._last_revision_info_cache is None:
 
425
            self._last_revision_info_cache = self._last_revision_info()
 
426
        return self._last_revision_info_cache
 
427
 
 
428
    def _last_revision_info(self):
421
429
        rh = self.revision_history()
422
430
        revno = len(rh)
423
431
        if revno:
484
492
            if not overwrite:
485
493
                if graph is None:
486
494
                    graph = self.repository.get_graph()
487
 
                if self._ensure_not_diverged(
 
495
                if self._check_if_descendant_or_diverged(
488
496
                        stop_revision, last_rev, graph, other):
489
497
                    # stop_revision is a descendant of last_rev, but we aren't
490
498
                    # overwriting, so we're done.
849
857
    def supports_tags(self):
850
858
        return self._format.supports_tags()
851
859
 
852
 
    def _ensure_not_diverged(self, revision_a, revision_b, graph, other_branch):
 
860
    def _check_if_descendant_or_diverged(self, revision_a, revision_b, graph,
 
861
                                         other_branch):
853
862
        """Ensure that revision_b is a descendant of revision_a.
854
863
 
855
864
        This is a helper function for update_revisions.
1494
1503
        """See Branch.set_revision_history."""
1495
1504
        if 'evil' in debug.debug_flags:
1496
1505
            mutter_callsite(3, "set_revision_history scales with history.")
 
1506
        check_not_reserved_id = _mod_revision.check_not_reserved_id
 
1507
        for rev_id in rev_history:
 
1508
            check_not_reserved_id(rev_id)
1497
1509
        self._write_revision_history(rev_history)
1498
1510
        self._clear_cached_state()
1499
1511
        self._cache_revision_history(rev_history)
1557
1569
            raise errors.NoSuchRevision(self, revision_id)
1558
1570
        current_rev_id = revision_id
1559
1571
        new_history = []
 
1572
        check_not_reserved_id = _mod_revision.check_not_reserved_id
1560
1573
        # Do not include ghosts or graph origin in revision_history
1561
1574
        while (current_rev_id in parents_map and
1562
1575
               len(parents_map[current_rev_id]) > 0):
 
1576
            check_not_reserved_id(current_rev_id)
1563
1577
            new_history.append(current_rev_id)
1564
1578
            current_rev_id = parents_map[current_rev_id][0]
1565
1579
            parents_map = graph.get_parent_map([current_rev_id])
1911
1925
 
1912
1926
    def __init__(self, *args, **kwargs):
1913
1927
        super(BzrBranch6, self).__init__(*args, **kwargs)
1914
 
        self._last_revision_info_cache = None
1915
1928
        self._partial_revision_history_cache = []
1916
1929
 
1917
1930
    def _clear_cached_state(self):
1918
1931
        super(BzrBranch6, self)._clear_cached_state()
1919
 
        self._last_revision_info_cache = None
1920
1932
        self._partial_revision_history_cache = []
1921
1933
 
1922
 
    @needs_read_lock
1923
 
    def last_revision_info(self):
1924
 
        """Return information about the last revision.
1925
 
 
1926
 
        :return: A tuple (revno, revision_id).
1927
 
        """
1928
 
        if self._last_revision_info_cache is None:
1929
 
            self._last_revision_info_cache = self._last_revision_info()
1930
 
        return self._last_revision_info_cache
1931
 
 
1932
1934
    def _last_revision_info(self):
1933
1935
        revision_string = self._transport.get_bytes('last-revision')
1934
1936
        revno, revision_id = revision_string.rstrip('\n').split(' ', 1)