2235
2235
return self.get_revision(revision_id).inventory_sha1
2237
def get_rev_id_for_revno(self, revno, known_pair):
2238
"""Return the revision id of a revno, given a later (revno, revid)
2239
pair in the same history.
2241
:return: if found (True, revid). If the available history ran out
2242
before reaching the revno, then this returns
2243
(False, (closest_revno, closest_revid)).
2245
known_revno, known_revid = known_pair
2246
partial_history = [known_revid]
2247
distance_from_known = known_revno - revno
2248
if distance_from_known < 0:
2250
'requested revno (%d) is later than given known revno (%d)'
2251
% (revno, known_revno))
2254
self, partial_history, stop_index=distance_from_known)
2255
except errors.RevisionNotPresent, err:
2256
if err.revision_id == known_revid:
2257
# The start revision (known_revid) wasn't found.
2259
# This is a stacked repository with no fallbacks, or a there's a
2260
# left-hand ghost. Either way, even though the revision named in
2261
# the error isn't in this repo, we know it's the next step in this
2262
# left-hand history.
2263
partial_history.append(err.revision_id)
2264
if len(partial_history) <= distance_from_known:
2265
# Didn't find enough history to get a revid for the revno.
2266
earliest_revno = known_revno - len(partial_history) + 1
2267
return (False, (earliest_revno, partial_history[-1]))
2268
if len(partial_history) - 1 > distance_from_known:
2269
raise AssertionError('_iter_for_revno returned too much history')
2270
return (True, partial_history[-1])
2237
2272
def iter_reverse_revision_history(self, revision_id):
2238
2273
"""Iterate backwards through revision ids in the lefthand history
4417
4452
yield versionedfile.FulltextContentFactory(
4418
4453
key, parent_keys, None, as_bytes)
4456
def _iter_for_revno(repo, partial_history_cache, stop_index=None,
4457
stop_revision=None):
4458
"""Extend the partial history to include a given index
4460
If a stop_index is supplied, stop when that index has been reached.
4461
If a stop_revision is supplied, stop when that revision is
4462
encountered. Otherwise, stop when the beginning of history is
4465
:param stop_index: The index which should be present. When it is
4466
present, history extension will stop.
4467
:param stop_revision: The revision id which should be present. When
4468
it is encountered, history extension will stop.
4470
start_revision = partial_history_cache[-1]
4471
iterator = repo.iter_reverse_revision_history(start_revision)
4473
#skip the last revision in the list
4476
if (stop_index is not None and
4477
len(partial_history_cache) > stop_index):
4479
if partial_history_cache[-1] == stop_revision:
4481
revision_id = iterator.next()
4482
partial_history_cache.append(revision_id)
4483
except StopIteration: