~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Lukáš Lalinský
  • Date: 2007-12-03 21:11:03 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-20071203211103-40soo8ldds0lyu2l
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.

Show diffs side-by-side

added added

removed removed

Lines of Context:
325
325
            # the branch object.
326
326
            from bzrlib.branch import Branch
327
327
            branch = Branch.open(branch_spec)
328
 
            # Need to use a new revision history
329
 
            # because we are using a specific branch
330
 
            revs = branch.revision_history()
 
328
            revs = None
331
329
 
332
330
        if dotted:
333
331
            branch.lock_read()
345
343
                # so for  API compatability we return None.
346
344
                return RevisionInfo(branch, None, revisions[0])
347
345
        else:
 
346
            last_revno, last_revision_id = branch.last_revision_info()
348
347
            if revno < 0:
349
348
                # if get_rev_id supported negative revnos, there would not be a
350
349
                # need for this special case.
351
 
                if (-revno) >= len(revs):
 
350
                if (-revno) >= last_revno:
352
351
                    revno = 1
353
352
                else:
354
 
                    revno = len(revs) + revno + 1
 
353
                    revno = last_revno + revno + 1
355
354
            try:
356
355
                revision_id = branch.get_rev_id(revno, revs)
357
356
            except errors.NoSuchRevision:
358
357
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
359
358
        return RevisionInfo(branch, revno, revision_id)
360
359
 
 
360
    def in_branch(self, branch, need_revno=True):
 
361
        return self._match_on(branch, None)
 
362
 
361
363
    def needs_branch(self):
362
364
        return self.spec.find(':') == -1
363
365
 
384
386
    Examples::
385
387
 
386
388
      revid:aaaa@bbbb-123456789 -> Select revision 'aaaa@bbbb-123456789'
387
 
    """    
 
389
    """
 
390
 
388
391
    prefix = 'revid:'
389
392
 
390
 
    def _match_on(self, branch, revs):
 
393
    def _match_on(self, branch, revs, need_revno=True):
391
394
        # self.spec comes straight from parsing the command line arguments,
392
395
        # so we expect it to be a Unicode string. Switch it to the internal
393
396
        # representation.
394
397
        revision_id = osutils.safe_revision_id(self.spec, warn=False)
395
 
        return RevisionInfo.from_revision_id(branch, revision_id, revs)
 
398
        if need_revno:
 
399
            if revs is None:
 
400
                # XXX Branch needs a method for incremental
 
401
                # revision_id -> revno resolving without loading
 
402
                # the whole history. (Lukas Lalinsky, 20081203)
 
403
                revs = branch.revision_history()
 
404
            return RevisionInfo.from_revision_id(branch, revision_id, revs)
 
405
        else:
 
406
            return RevisionInfo(branch, None, revision_id)
 
407
 
 
408
    def in_branch(self, branch, need_revno=True):
 
409
        # Same as RevisionSpec.in_history, but without history loading.
 
410
        return self._match_on(branch, None, need_revno)
396
411
 
397
412
SPEC_TYPES.append(RevisionSpec_revid)
398
413