~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-30 01:02:36 UTC
  • mfrom: (3449.2.8 uncommit_perf)
  • Revision ID: pqm@pqm.ubuntu.com-20080530010236-e3x7ckdc25s57pgc
(jam) Speed up 'bzr uncommit' by avoiding loading the whole revision
        history (bug #172649)

Show diffs side-by-side

added added

removed removed

Lines of Context:
335
335
 
336
336
    :return: A (mainline_revs, rev_nos, start_rev_id, end_rev_id) tuple.
337
337
    """
338
 
    which_revs = _enumerate_history(branch)
339
 
    if not which_revs:
 
338
    branch_revno, branch_last_revision = branch.last_revision_info()
 
339
    if branch_revno == 0:
340
340
        return None, None, None, None
341
341
 
342
342
    # For mainline generation, map start_revision and end_revision to 
349
349
    if start_revision is None:
350
350
        start_revno = 1
351
351
    else:
352
 
        if isinstance(start_revision,RevisionInfo):
 
352
        if isinstance(start_revision, RevisionInfo):
353
353
            start_rev_id = start_revision.rev_id
354
354
            start_revno = start_revision.revno or 1
355
355
        else:
358
358
    
359
359
    end_rev_id = None
360
360
    if end_revision is None:
361
 
        end_revno = len(which_revs)
 
361
        end_revno = branch_revno
362
362
    else:
363
 
        if isinstance(end_revision,RevisionInfo):
 
363
        if isinstance(end_revision, RevisionInfo):
364
364
            end_rev_id = end_revision.rev_id
365
 
            end_revno = end_revision.revno or len(which_revs)
 
365
            end_revno = end_revision.revno or branch_revno
366
366
        else:
367
367
            branch.check_real_revno(end_revision)
368
368
            end_revno = end_revision
374
374
        raise BzrCommandError("Start revision must be older than "
375
375
                              "the end revision.")
376
376
 
377
 
    # list indexes are 0-based; revisions are 1-based
378
 
    cut_revs = which_revs[(start_revno-1):(end_revno)]
379
 
    if not cut_revs:
 
377
    if end_revno < start_revno:
380
378
        return None, None, None, None
 
379
    cur_revno = branch_revno
 
380
    rev_nos = {}
 
381
    mainline_revs = []
 
382
    for revision_id in branch.repository.iter_reverse_revision_history(
 
383
                        branch_last_revision):
 
384
        if cur_revno < start_revno:
 
385
            # We have gone far enough, but we always add 1 more revision
 
386
            rev_nos[revision_id] = cur_revno
 
387
            mainline_revs.append(revision_id)
 
388
            break
 
389
        if cur_revno <= end_revno:
 
390
            rev_nos[revision_id] = cur_revno
 
391
            mainline_revs.append(revision_id)
 
392
        cur_revno -= 1
 
393
    else:
 
394
        # We walked off the edge of all revisions, so we add a 'None' marker
 
395
        mainline_revs.append(None)
381
396
 
382
 
    # convert the revision history to a dictionary:
383
 
    rev_nos = dict((k, v) for v, k in cut_revs)
 
397
    mainline_revs.reverse()
384
398
 
385
399
    # override the mainline to look like the revision history.
386
 
    mainline_revs = [revision_id for index, revision_id in cut_revs]
387
 
    if cut_revs[0][0] == 1:
388
 
        mainline_revs.insert(0, None)
389
 
    else:
390
 
        mainline_revs.insert(0, which_revs[start_revno-2][1])
391
400
    return mainline_revs, rev_nos, start_rev_id, end_rev_id
392
401
 
393
402