/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/revisionspec.py

  • Committer: Lukáš Lalinský
  • Date: 2007-12-03 20:48:08 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-20071203204808-gv1m751xdb8m9ltc
Make RevisionSpec_last not load the whole history.

Implement BzrBranch6.get_rev_id, that uses last_revision_info and repository.iter_reverse_revision_history to find out the revision_id incrementally without loading the whole history.

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
    # aliases for now, when we fix the core logic, then they
233
233
    # will do what you expect.
234
234
    in_store = in_history
235
 
    in_branch = in_store
236
 
        
 
235
 
 
236
    def in_branch(self, branch, need_revno=True):
 
237
        """Evaluate this revision spec and return a RevisionInfo object.
 
238
 
 
239
        If need_revno is False, the returned RevisionInfo object might
 
240
        have the revno attribute set as None (for performance reasons),
 
241
        even if the revno exists in the specified branch.
 
242
 
 
243
        The default implementation is an alias for RevisionSpec.in_history.
 
244
        """
 
245
        return self.in_history(branch)
 
246
 
237
247
    def __repr__(self):
238
248
        # this is mostly for helping with testing
239
249
        return '<%s %s>' % (self.__class__.__name__,
347
357
            except errors.NoSuchRevision:
348
358
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
349
359
        return RevisionInfo(branch, revno, revision_id)
350
 
        
 
360
 
351
361
    def needs_branch(self):
352
362
        return self.spec.find(':') == -1
353
363
 
398
408
 
399
409
      last:1        -> return the last revision
400
410
      last:3        -> return the revision 2 before the end.
401
 
    """    
 
411
    """
402
412
 
403
413
    prefix = 'last:'
404
414
 
405
415
    def _match_on(self, branch, revs):
 
416
        last_revno, last_revision_id = branch.last_revision_info()
 
417
 
406
418
        if self.spec == '':
407
 
            if not revs:
 
419
            if not last_revno:
408
420
                raise errors.NoCommits(branch)
409
 
            return RevisionInfo(branch, len(revs), revs[-1])
 
421
            return RevisionInfo(branch, last_revno, last_revision_id)
410
422
 
411
423
        try:
412
424
            offset = int(self.spec)
416
428
        if offset <= 0:
417
429
            raise errors.InvalidRevisionSpec(self.user_spec, branch,
418
430
                                             'you must supply a positive value')
419
 
        revno = len(revs) - offset + 1
 
431
 
 
432
        revno = last_revno - offset + 1
420
433
        try:
421
434
            revision_id = branch.get_rev_id(revno, revs)
422
435
        except errors.NoSuchRevision:
423
436
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
424
437
        return RevisionInfo(branch, revno, revision_id)
425
438
 
 
439
    def in_branch(self, branch, need_revno=True):
 
440
        # Same as RevisionSpec.in_history, but without history loading.
 
441
        return self._match_on(branch, None)
 
442
 
 
443
 
426
444
SPEC_TYPES.append(RevisionSpec_last)
427
445
 
428
446