2258
2258
return self.get_revision(revision_id).inventory_sha1
2260
def get_rev_id_for_revno(self, revno, known_pair):
2261
"""Return the revision id of a revno, given a later (revno, revid)
2262
pair in the same history.
2264
:return: if found (True, revid). If the available history ran out
2265
before reaching the revno, then this returns
2266
(False, (closest_revno, closest_revid)).
2268
known_revno, known_revid = known_pair
2269
partial_history = [known_revid]
2270
distance_from_known = known_revno - revno
2271
if distance_from_known < 0:
2273
'requested revno (%d) is later than given known revno (%d)'
2274
% (revno, known_revno))
2277
self, partial_history, stop_index=distance_from_known)
2278
except errors.RevisionNotPresent, err:
2279
if err.revision_id == known_revid:
2280
# The start revision (known_revid) wasn't found.
2282
# This is a stacked repository with no fallbacks, or a there's a
2283
# left-hand ghost. Either way, even though the revision named in
2284
# the error isn't in this repo, we know it's the next step in this
2285
# left-hand history.
2286
partial_history.append(err.revision_id)
2287
if len(partial_history) <= distance_from_known:
2288
# Didn't find enough history to get a revid for the revno.
2289
earliest_revno = known_revno - len(partial_history) + 1
2290
return (False, (earliest_revno, partial_history[-1]))
2291
if len(partial_history) - 1 > distance_from_known:
2292
raise AssertionError('_iter_for_revno returned too much history')
2293
return (True, partial_history[-1])
2260
2295
def iter_reverse_revision_history(self, revision_id):
2261
2296
"""Iterate backwards through revision ids in the lefthand history
2269
2304
if next_id in (None, _mod_revision.NULL_REVISION):
2307
parents = graph.get_parent_map([next_id])[next_id]
2309
raise errors.RevisionNotPresent(next_id, self)
2272
# Note: The following line may raise KeyError in the event of
2273
# truncated history. We decided not to have a try:except:raise
2274
# RevisionNotPresent here until we see a use for it, because of the
2275
# cost in an inner loop that is by its very nature O(history).
2276
# Robert Collins 20080326
2277
parents = graph.get_parent_map([next_id])[next_id]
2278
2311
if len(parents) == 0:
2409
2442
return self.control_files.get_transaction()
2411
2444
def get_parent_map(self, revision_ids):
2412
"""See graph._StackedParentsProvider.get_parent_map"""
2445
"""See graph.StackedParentsProvider.get_parent_map"""
2413
2446
# revisions index works in keys; this just works in revisions
2414
2447
# therefore wrap and unwrap
2415
2448
query_keys = []
2438
2471
parents_provider = self._make_parents_provider()
2439
2472
if (other_repository is not None and
2440
2473
not self.has_same_location(other_repository)):
2441
parents_provider = graph._StackedParentsProvider(
2474
parents_provider = graph.StackedParentsProvider(
2442
2475
[parents_provider, other_repository._make_parents_provider()])
2443
2476
return graph.Graph(parents_provider)
3085
3118
'RepositoryFormatCHK1',
3121
format_registry.register_lazy(
3122
'Bazaar development format - chk repository with bencode revision '
3123
'serialization (needs bzr.dev from 1.16)\n',
3124
'bzrlib.repofmt.groupcompress_repo',
3125
'RepositoryFormatCHK2',
3127
format_registry.register_lazy(
3128
'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
3129
'bzrlib.repofmt.groupcompress_repo',
3130
'RepositoryFormat2a',
3089
3134
class InterRepository(InterObject):
3090
3135
"""This class represents operations taking place between two repositories.
4291
4336
yield versionedfile.FulltextContentFactory(
4292
4337
key, parent_keys, None, as_bytes)
4340
def _iter_for_revno(repo, partial_history_cache, stop_index=None,
4341
stop_revision=None):
4342
"""Extend the partial history to include a given index
4344
If a stop_index is supplied, stop when that index has been reached.
4345
If a stop_revision is supplied, stop when that revision is
4346
encountered. Otherwise, stop when the beginning of history is
4349
:param stop_index: The index which should be present. When it is
4350
present, history extension will stop.
4351
:param stop_revision: The revision id which should be present. When
4352
it is encountered, history extension will stop.
4354
start_revision = partial_history_cache[-1]
4355
iterator = repo.iter_reverse_revision_history(start_revision)
4357
#skip the last revision in the list
4360
if (stop_index is not None and
4361
len(partial_history_cache) > stop_index):
4363
if partial_history_cache[-1] == stop_revision:
4365
revision_id = iterator.next()
4366
partial_history_cache.append(revision_id)
4367
except StopIteration: