~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Lukáš Lalinský
  • Date: 2007-12-03 23:03:59 UTC
  • mto: (3298.2.1 get_rev_id)
  • mto: This revision was merged to the branch mainline in revision 3328.
  • Revision ID: lalinsky@gmail.com-20071203230359-lhcqc1peusply2cc
Implement partial history cache in BzrBranch6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1912
1912
    def __init__(self, *ignored, **ignored_too):
1913
1913
        super(BzrBranch6, self).__init__(*ignored, **ignored_too)
1914
1914
        self._last_revision_info_cache = None
 
1915
        self._partial_revision_history_cache = None
1915
1916
 
1916
1917
    def _clear_cached_state(self):
1917
1918
        super(BzrBranch6, self)._clear_cached_state()
1918
1919
        self._last_revision_info_cache = None
 
1920
        self._partial_revision_history_cache = None
1919
1921
 
1920
1922
    @needs_read_lock
1921
1923
    def last_revision_info(self):
1968
1970
    def _gen_revision_history(self):
1969
1971
        """Generate the revision history from last revision
1970
1972
        """
 
1973
        if self._partial_revision_history_cache:
 
1974
            last_revision = self._partial_revision_history_cache.pop(-1)
 
1975
            partial_history = self._partial_revision_history_cache
 
1976
            partial_history.reverse()
 
1977
            self._partial_revision_history_cache = None
 
1978
        else:
 
1979
            last_revision = self.last_revision()
 
1980
            partial_history = []
1971
1981
        history = list(self.repository.iter_reverse_revision_history(
1972
 
            self.last_revision()))
 
1982
            last_revision))
1973
1983
        history.reverse()
1974
 
        return history
 
1984
        return history + partial_history
1975
1985
 
1976
1986
    def _write_revision_history(self, history):
1977
1987
        """Factored out of set_revision_history.
2099
2109
        if history is not None:
2100
2110
            return history[revno - 1]
2101
2111
 
2102
 
        # TODO cache the partially loaded history (Lukas Lalinsky, 20081203)
2103
 
        revision_id = last_revision_id
 
2112
        distance = last_revno - revno
 
2113
        if self._partial_revision_history_cache:
 
2114
            try:
 
2115
                return self._partial_revision_history_cache[distance]
 
2116
            except IndexError:
 
2117
                pass
 
2118
            distance -= len(self._partial_revision_history_cache) - 1
 
2119
            revision_id = self._partial_revision_history_cache[-1]
 
2120
        else:
 
2121
            self._partial_revision_history_cache = [last_revision_id]
 
2122
            revision_id = last_revision_id
 
2123
 
2104
2124
        history_iter = self.repository.iter_reverse_revision_history(
2105
 
            last_revision_id)
2106
 
        for i in xrange(last_revno - revno + 1):
 
2125
            revision_id)
 
2126
        history_iter.next()
 
2127
        for i in xrange(distance):
2107
2128
            try:
2108
2129
                revision_id = history_iter.next()
2109
2130
            except StopIteration:
2110
2131
                raise errors.NoSuchRevision(self, revno)
 
2132
            self._partial_revision_history_cache.append(revision_id)
2111
2133
        return revision_id
2112
2134
 
2113
2135