/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-17 17:57:15 UTC
  • mfrom: (4454 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4460.
  • Revision ID: john@arbash-meinel.com-20090617175715-p9ebpwx5rhc0qin1
Merge bzr.dev 4454 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2257
2257
        """
2258
2258
        return self.get_revision(revision_id).inventory_sha1
2259
2259
 
 
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.
 
2263
 
 
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)).
 
2267
        """
 
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:
 
2272
            raise ValueError(
 
2273
                'requested revno (%d) is later than given known revno (%d)'
 
2274
                % (revno, known_revno))
 
2275
        try:
 
2276
            _iter_for_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.
 
2281
                raise
 
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])
 
2294
 
2260
2295
    def iter_reverse_revision_history(self, revision_id):
2261
2296
        """Iterate backwards through revision ids in the lefthand history
2262
2297
 
2268
2303
        while True:
2269
2304
            if next_id in (None, _mod_revision.NULL_REVISION):
2270
2305
                return
 
2306
            try:
 
2307
                parents = graph.get_parent_map([next_id])[next_id]
 
2308
            except KeyError:
 
2309
                raise errors.RevisionNotPresent(next_id, self)
2271
2310
            yield next_id
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:
2279
2312
                return
2280
2313
            else:
2409
2442
        return self.control_files.get_transaction()
2410
2443
 
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)
2444
2477
 
3085
3118
    'RepositoryFormatCHK1',
3086
3119
    )
3087
3120
 
 
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',
 
3126
    )
 
3127
format_registry.register_lazy(
 
3128
    'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
 
3129
    'bzrlib.repofmt.groupcompress_repo',
 
3130
    'RepositoryFormat2a',
 
3131
    )
 
3132
 
3088
3133
 
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)
4293
4338
 
 
4339
 
 
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
 
4343
 
 
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
 
4347
    reached.
 
4348
 
 
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.
 
4353
    """
 
4354
    start_revision = partial_history_cache[-1]
 
4355
    iterator = repo.iter_reverse_revision_history(start_revision)
 
4356
    try:
 
4357
        #skip the last revision in the list
 
4358
        iterator.next()
 
4359
        while True:
 
4360
            if (stop_index is not None and
 
4361
                len(partial_history_cache) > stop_index):
 
4362
                break
 
4363
            if partial_history_cache[-1] == stop_revision:
 
4364
                break
 
4365
            revision_id = iterator.next()
 
4366
            partial_history_cache.append(revision_id)
 
4367
    except StopIteration:
 
4368
        # No more history
 
4369
        return
 
4370