1377
1377
"""See Branch.set_revision_history."""
1378
1378
if 'evil' in debug.debug_flags:
1379
1379
mutter_callsite(3, "set_revision_history scales with history.")
1380
self._clear_cached_state()
1381
1380
self._write_revision_history(rev_history)
1381
self._clear_cached_state()
1382
1382
self._cache_revision_history(rev_history)
1383
1383
for hook in Branch.hooks['set_rh']:
1384
1384
hook(self, rev_history)
1812
1812
class BzrBranch6(BzrBranch5):
1814
def __init__(self, *args, **kwargs):
1815
super(BzrBranch6, self).__init__(*args, **kwargs)
1816
self._last_revision_info_cache = None
1817
self._partial_revision_history_cache = []
1819
def _clear_cached_state(self):
1820
super(BzrBranch6, self)._clear_cached_state()
1821
self._last_revision_info_cache = None
1822
self._partial_revision_history_cache = []
1814
1824
@needs_read_lock
1815
1825
def last_revision_info(self):
1826
"""Return information about the last revision.
1828
:return: A tuple (revno, revision_id).
1830
if self._last_revision_info_cache is None:
1831
self._last_revision_info_cache = self._last_revision_info()
1832
return self._last_revision_info_cache
1834
def _last_revision_info(self):
1816
1835
revision_string = self.control_files.get('last-revision').read()
1817
1836
revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
1818
1837
revision_id = cache_utf8.get_cached_utf8(revision_id)
1839
1858
self._check_history_violation(revision_id)
1840
1859
self._write_last_revision_info(revno, revision_id)
1841
1860
self._clear_cached_state()
1861
self._last_revision_info_cache = revno, revision_id
1843
1863
def _check_history_violation(self, revision_id):
1844
1864
last_revision = _mod_revision.ensure_null(self.last_revision())
1850
1870
def _gen_revision_history(self):
1851
1871
"""Generate the revision history from last revision
1853
history = list(self.repository.iter_reverse_revision_history(
1854
self.last_revision()))
1873
self._extend_partial_history()
1874
return list(reversed(self._partial_revision_history_cache))
1876
def _extend_partial_history(self, stop_index=None, stop_revision=None):
1877
"""Extend the partial history to include a given index
1879
If a stop_index is supplied, stop when that index has been reached.
1880
If a stop_revision is supplied, stop when that revision is
1881
encountered. Otherwise, stop when the beginning of history is
1884
:param stop_index: The index which should be present. When it is
1885
present, history extension will stop.
1886
:param revision_id: The revision id which should be present. When
1887
it is encountered, history extension will stop.
1889
repo = self.repository
1890
if len(self._partial_revision_history_cache) == 0:
1891
iterator = repo.iter_reverse_revision_history(self.last_revision())
1893
start_revision = self._partial_revision_history_cache[-1]
1894
iterator = repo.iter_reverse_revision_history(start_revision)
1895
#skip the last revision in the list
1896
next_revision = iterator.next()
1897
assert next_revision == start_revision
1898
for revision_id in iterator:
1899
self._partial_revision_history_cache.append(revision_id)
1900
if (stop_index is not None and
1901
len(self._partial_revision_history_cache) > stop_index):
1903
if revision_id == stop_revision:
1858
1906
def _write_revision_history(self, history):
1859
1907
"""Factored out of set_revision_history.
1971
2019
revno = len(history)
1972
2020
self.set_last_revision_info(revno, revision_id)
2023
def get_rev_id(self, revno, history=None):
2024
"""Find the revision id of the specified revno."""
2026
return _mod_revision.NULL_REVISION
2028
last_revno, last_revision_id = self.last_revision_info()
2029
if revno <= 0 or revno > last_revno:
2030
raise errors.NoSuchRevision(self, revno)
2032
if history is not None:
2033
assert len(history) == last_revno, 'revno/history mismatch'
2034
return history[revno - 1]
2036
index = last_revno - revno
2037
if len(self._partial_revision_history_cache) <= index:
2038
self._extend_partial_history(stop_index=index)
2039
if len(self._partial_revision_history_cache) > index:
2040
return self._partial_revision_history_cache[index]
2042
raise errors.NoSuchRevision(self, revno)
2045
def revision_id_to_revno(self, revision_id):
2046
"""Given a revision id, return its revno"""
2047
if _mod_revision.is_null(revision_id):
2050
index = self._partial_revision_history_cache.index(revision_id)
2052
self._extend_partial_history(stop_revision=revision_id)
2053
index = len(self._partial_revision_history_cache) - 1
2054
if self._partial_revision_history_cache[index] != revision_id:
2055
raise errors.NoSuchRevision(self, revision_id)
2056
return self.revno() - index
1975
2059
######################################################################
1976
2060
# results of operations