~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: 2010-04-14 15:06:30 UTC
  • mfrom: (5129.1.3 cleanup-log-direction)
  • Revision ID: pqm@pqm.ubuntu.com-20100414150630-f2y00b4pm6lemb2o
(vila) Slight refactoring of direction handling in log code. (Vincent
 Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
455
455
        generate_merge_revisions = rqst.get('levels') != 1
456
456
        delayed_graph_generation = not rqst.get('specific_fileids') and (
457
457
                rqst.get('limit') or self.start_rev_id or self.end_rev_id)
458
 
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
459
 
            self.end_rev_id, rqst.get('direction'), generate_merge_revisions,
 
458
        view_revisions = _calc_view_revisions(
 
459
            self.branch, self.start_rev_id, self.end_rev_id,
 
460
            rqst.get('direction'),
 
461
            generate_merge_revisions=generate_merge_revisions,
460
462
            delayed_graph_generation=delayed_graph_generation)
461
463
 
462
464
        # Apply the other filters
470
472
        # Note that we always generate the merge revisions because
471
473
        # filter_revisions_touching_file_id() requires them ...
472
474
        rqst = self.rqst
473
 
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
474
 
            self.end_rev_id, rqst.get('direction'), True)
 
475
        view_revisions = _calc_view_revisions(
 
476
            self.branch, self.start_rev_id, self.end_rev_id,
 
477
            rqst.get('direction'), generate_merge_revisions=True)
475
478
        if not isinstance(view_revisions, list):
476
479
            view_revisions = list(view_revisions)
477
480
        view_revisions = _filter_revisions_touching_file_id(self.branch,
488
491
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
489
492
             a list of the same tuples.
490
493
    """
 
494
    if direction not in ('reverse', 'forward'):
 
495
        raise ValueError('invalid direction %r' % direction)
491
496
    br_revno, br_rev_id = branch.last_revision_info()
492
497
    if br_revno == 0:
493
498
        return []
494
499
 
495
 
    # If a single revision is requested, check we can handle it
496
 
    generate_single_revision = (end_rev_id and start_rev_id == end_rev_id and
497
 
        (not generate_merge_revisions or not _has_merges(branch, end_rev_id)))
498
 
    if generate_single_revision:
499
 
        return _generate_one_revision(branch, end_rev_id, br_rev_id, br_revno)
500
 
 
501
 
    # If we only want to see linear revisions, we can iterate ...
502
 
    if not generate_merge_revisions:
503
 
        return _generate_flat_revisions(branch, start_rev_id, end_rev_id,
504
 
            direction)
 
500
    if (end_rev_id and start_rev_id == end_rev_id
 
501
        and (not generate_merge_revisions
 
502
             or not _has_merges(branch, end_rev_id))):
 
503
        # If a single revision is requested, check we can handle it
 
504
        iter_revs = _generate_one_revision(branch, end_rev_id, br_rev_id,
 
505
                                           br_revno)
 
506
    elif not generate_merge_revisions:
 
507
        # If we only want to see linear revisions, we can iterate ...
 
508
        iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
 
509
                                             direction)
 
510
        if direction == 'forward':
 
511
            iter_revs = reversed(iter_revs)
505
512
    else:
506
 
        return _generate_all_revisions(branch, start_rev_id, end_rev_id,
507
 
            direction, delayed_graph_generation)
 
513
        iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
 
514
                                            direction, delayed_graph_generation)
 
515
        if direction == 'forward':
 
516
            iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
 
517
    return iter_revs
508
518
 
509
519
 
510
520
def _generate_one_revision(branch, rev_id, br_rev_id, br_revno):
528
538
        except _StartNotLinearAncestor:
529
539
            raise errors.BzrCommandError('Start revision not found in'
530
540
                ' left-hand history of end revision.')
531
 
    if direction == 'forward':
532
 
        result = reversed(result)
533
541
    return result
534
542
 
535
543
 
569
577
                    initial_revisions.append((rev_id, revno, depth))
570
578
            else:
571
579
                # No merged revisions found
572
 
                if direction == 'reverse':
573
 
                    return initial_revisions
574
 
                elif direction == 'forward':
575
 
                    return reversed(initial_revisions)
576
 
                else:
577
 
                    raise ValueError('invalid direction %r' % direction)
 
580
                return initial_revisions
578
581
        except _StartNotLinearAncestor:
579
582
            # A merge was never detected so the lower revision limit can't
580
583
            # be nested down somewhere
592
595
    view_revisions = chain(iter(initial_revisions),
593
596
        _graph_view_revisions(branch, start_rev_id, end_rev_id,
594
597
                              rebase_initial_depths=(direction == 'reverse')))
595
 
    if direction == 'reverse':
596
 
        return view_revisions
597
 
    elif direction == 'forward':
598
 
        # Forward means oldest first, adjusting for depth.
599
 
        view_revisions = reverse_by_depth(list(view_revisions))
600
 
        return _rebase_merge_depth(view_revisions)
601
 
    else:
602
 
        raise ValueError('invalid direction %r' % direction)
 
598
    return view_revisions
603
599
 
604
600
 
605
601
def _has_merges(branch, rev_id):