~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Martin Pool
  • Date: 2010-02-03 00:08:23 UTC
  • mto: This revision was merged to the branch mainline in revision 5002.
  • Revision ID: mbp@sourcefrog.net-20100203000823-fcyf2791xrl3fbfo
expand tabs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
109
109
    last_path = None
110
110
    revno = 1
111
111
    for revision_id in branch.revision_history():
112
 
        this_inv = branch.repository.get_inventory(revision_id)
 
112
        this_inv = branch.repository.get_revision_inventory(revision_id)
113
113
        if file_id in this_inv:
114
114
            this_ie = this_inv[file_id]
115
115
            this_path = this_inv.id2path(file_id)
220
220
    'direction': 'reverse',
221
221
    'levels': 1,
222
222
    'generate_tags': True,
223
 
    'exclude_common_ancestry': False,
224
223
    '_match_using_deltas': True,
225
224
    }
226
225
 
227
226
 
228
227
def make_log_request_dict(direction='reverse', specific_fileids=None,
229
 
                          start_revision=None, end_revision=None, limit=None,
230
 
                          message_search=None, levels=1, generate_tags=True,
231
 
                          delta_type=None,
232
 
                          diff_type=None, _match_using_deltas=True,
233
 
                          exclude_common_ancestry=False,
234
 
                          ):
 
228
    start_revision=None, end_revision=None, limit=None,
 
229
    message_search=None, levels=1, generate_tags=True, delta_type=None,
 
230
    diff_type=None, _match_using_deltas=True):
235
231
    """Convenience function for making a logging request dictionary.
236
232
 
237
233
    Using this function may make code slightly safer by ensuring
275
271
      algorithm used for matching specific_fileids. This parameter
276
272
      may be removed in the future so bzrlib client code should NOT
277
273
      use it.
278
 
 
279
 
    :param exclude_common_ancestry: Whether -rX..Y should be interpreted as a
280
 
      range operator or as a graph difference.
281
274
    """
282
275
    return {
283
276
        'direction': direction,
290
283
        'generate_tags': generate_tags,
291
284
        'delta_type': delta_type,
292
285
        'diff_type': diff_type,
293
 
        'exclude_common_ancestry': exclude_common_ancestry,
294
286
        # Add 'private' attributes for features that may be deprecated
295
287
        '_match_using_deltas': _match_using_deltas,
296
288
    }
463
455
        generate_merge_revisions = rqst.get('levels') != 1
464
456
        delayed_graph_generation = not rqst.get('specific_fileids') and (
465
457
                rqst.get('limit') or self.start_rev_id or self.end_rev_id)
466
 
        view_revisions = _calc_view_revisions(
467
 
            self.branch, self.start_rev_id, self.end_rev_id,
468
 
            rqst.get('direction'),
469
 
            generate_merge_revisions=generate_merge_revisions,
470
 
            delayed_graph_generation=delayed_graph_generation,
471
 
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
 
458
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
 
459
            self.end_rev_id, rqst.get('direction'), generate_merge_revisions,
 
460
            delayed_graph_generation=delayed_graph_generation)
472
461
 
473
462
        # Apply the other filters
474
463
        return make_log_rev_iterator(self.branch, view_revisions,
481
470
        # Note that we always generate the merge revisions because
482
471
        # filter_revisions_touching_file_id() requires them ...
483
472
        rqst = self.rqst
484
 
        view_revisions = _calc_view_revisions(
485
 
            self.branch, self.start_rev_id, self.end_rev_id,
486
 
            rqst.get('direction'), generate_merge_revisions=True,
487
 
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
 
473
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
 
474
            self.end_rev_id, rqst.get('direction'), True)
488
475
        if not isinstance(view_revisions, list):
489
476
            view_revisions = list(view_revisions)
490
477
        view_revisions = _filter_revisions_touching_file_id(self.branch,
495
482
 
496
483
 
497
484
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
498
 
                         generate_merge_revisions,
499
 
                         delayed_graph_generation=False,
500
 
                         exclude_common_ancestry=False,
501
 
                         ):
 
485
    generate_merge_revisions, delayed_graph_generation=False):
502
486
    """Calculate the revisions to view.
503
487
 
504
488
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
505
489
             a list of the same tuples.
506
490
    """
507
 
    if (exclude_common_ancestry and start_rev_id == end_rev_id):
508
 
        raise errors.BzrCommandError(
509
 
            '--exclude-common-ancestry requires two different revisions')
510
 
    if direction not in ('reverse', 'forward'):
511
 
        raise ValueError('invalid direction %r' % direction)
512
491
    br_revno, br_rev_id = branch.last_revision_info()
513
492
    if br_revno == 0:
514
493
        return []
515
494
 
516
 
    if (end_rev_id and start_rev_id == end_rev_id
517
 
        and (not generate_merge_revisions
518
 
             or not _has_merges(branch, end_rev_id))):
519
 
        # If a single revision is requested, check we can handle it
520
 
        iter_revs = _generate_one_revision(branch, end_rev_id, br_rev_id,
521
 
                                           br_revno)
522
 
    elif not generate_merge_revisions:
523
 
        # If we only want to see linear revisions, we can iterate ...
524
 
        iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
525
 
                                             direction)
526
 
        if direction == 'forward':
527
 
            iter_revs = reversed(iter_revs)
 
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)
528
505
    else:
529
 
        iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
530
 
                                            direction, delayed_graph_generation,
531
 
                                            exclude_common_ancestry)
532
 
        if direction == 'forward':
533
 
            iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
534
 
    return iter_revs
 
506
        return _generate_all_revisions(branch, start_rev_id, end_rev_id,
 
507
            direction, delayed_graph_generation)
535
508
 
536
509
 
537
510
def _generate_one_revision(branch, rev_id, br_rev_id, br_revno):
555
528
        except _StartNotLinearAncestor:
556
529
            raise errors.BzrCommandError('Start revision not found in'
557
530
                ' left-hand history of end revision.')
 
531
    if direction == 'forward':
 
532
        result = reversed(result)
558
533
    return result
559
534
 
560
535
 
561
536
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
562
 
                            delayed_graph_generation,
563
 
                            exclude_common_ancestry=False):
 
537
    delayed_graph_generation):
564
538
    # On large trees, generating the merge graph can take 30-60 seconds
565
539
    # so we delay doing it until a merge is detected, incrementally
566
540
    # returning initial (non-merge) revisions while we can.
567
 
 
568
 
    # The above is only true for old formats (<= 0.92), for newer formats, a
569
 
    # couple of seconds only should be needed to load the whole graph and the
570
 
    # other graph operations needed are even faster than that -- vila 100201
571
541
    initial_revisions = []
572
542
    if delayed_graph_generation:
573
543
        try:
574
 
            for rev_id, revno, depth in  _linear_view_revisions(
575
 
                branch, start_rev_id, end_rev_id):
 
544
            for rev_id, revno, depth in \
 
545
                _linear_view_revisions(branch, start_rev_id, end_rev_id):
576
546
                if _has_merges(branch, rev_id):
577
 
                    # The end_rev_id can be nested down somewhere. We need an
578
 
                    # explicit ancestry check. There is an ambiguity here as we
579
 
                    # may not raise _StartNotLinearAncestor for a revision that
580
 
                    # is an ancestor but not a *linear* one. But since we have
581
 
                    # loaded the graph to do the check (or calculate a dotted
582
 
                    # revno), we may as well accept to show the log...  We need
583
 
                    # the check only if start_rev_id is not None as all
584
 
                    # revisions have _mod_revision.NULL_REVISION as an ancestor
585
 
                    # -- vila 20100319
586
 
                    graph = branch.repository.get_graph()
587
 
                    if (start_rev_id is not None
588
 
                        and not graph.is_ancestor(start_rev_id, end_rev_id)):
589
 
                        raise _StartNotLinearAncestor()
590
 
                    # Since we collected the revisions so far, we need to
591
 
                    # adjust end_rev_id.
592
547
                    end_rev_id = rev_id
593
548
                    break
594
549
                else:
595
550
                    initial_revisions.append((rev_id, revno, depth))
596
551
            else:
597
552
                # No merged revisions found
598
 
                return initial_revisions
 
553
                if direction == 'reverse':
 
554
                    return initial_revisions
 
555
                elif direction == 'forward':
 
556
                    return reversed(initial_revisions)
 
557
                else:
 
558
                    raise ValueError('invalid direction %r' % direction)
599
559
        except _StartNotLinearAncestor:
600
560
            # A merge was never detected so the lower revision limit can't
601
561
            # be nested down somewhere
602
562
            raise errors.BzrCommandError('Start revision not found in'
603
563
                ' history of end revision.')
604
564
 
605
 
    # We exit the loop above because we encounter a revision with merges, from
606
 
    # this revision, we need to switch to _graph_view_revisions.
607
 
 
608
565
    # A log including nested merges is required. If the direction is reverse,
609
566
    # we rebase the initial merge depths so that the development line is
610
567
    # shown naturally, i.e. just like it is for linear logging. We can easily
612
569
    # indented at the end seems slightly nicer in that case.
613
570
    view_revisions = chain(iter(initial_revisions),
614
571
        _graph_view_revisions(branch, start_rev_id, end_rev_id,
615
 
                              rebase_initial_depths=(direction == 'reverse'),
616
 
                              exclude_common_ancestry=exclude_common_ancestry))
617
 
    return view_revisions
 
572
        rebase_initial_depths=direction == 'reverse'))
 
573
    if direction == 'reverse':
 
574
        return view_revisions
 
575
    elif direction == 'forward':
 
576
        # Forward means oldest first, adjusting for depth.
 
577
        view_revisions = reverse_by_depth(list(view_revisions))
 
578
        return _rebase_merge_depth(view_revisions)
 
579
    else:
 
580
        raise ValueError('invalid direction %r' % direction)
618
581
 
619
582
 
620
583
def _has_merges(branch, rev_id):
678
641
 
679
642
 
680
643
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
681
 
                          rebase_initial_depths=True,
682
 
                          exclude_common_ancestry=False):
 
644
    rebase_initial_depths=True):
683
645
    """Calculate revisions to view including merges, newest to oldest.
684
646
 
685
647
    :param branch: the branch
689
651
      revision is found?
690
652
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
691
653
    """
692
 
    if exclude_common_ancestry:
693
 
        stop_rule = 'with-merges-without-common-ancestry'
694
 
    else:
695
 
        stop_rule = 'with-merges'
696
654
    view_revisions = branch.iter_merge_sorted_revisions(
697
655
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
698
 
        stop_rule=stop_rule)
 
656
        stop_rule="with-merges")
699
657
    if not rebase_initial_depths:
700
658
        for (rev_id, merge_depth, revno, end_of_merge
701
659
             ) in view_revisions:
1452
1410
        """
1453
1411
        # Revision comes directly from a foreign repository
1454
1412
        if isinstance(rev, foreign.ForeignRevision):
1455
 
            return self._format_properties(
1456
 
                rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
 
1413
            return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
1457
1414
 
1458
1415
        # Imported foreign revision revision ids always contain :
1459
1416
        if not ":" in rev.revision_id:
1546
1503
        to_file = self.to_file
1547
1504
        to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1548
1505
        if revision.delta is not None:
1549
 
            # Use the standard status output to display changes
1550
 
            from bzrlib.delta import report_delta
1551
 
            report_delta(to_file, revision.delta, short_status=False, 
1552
 
                         show_ids=self.show_ids, indent=indent)
 
1506
            # We don't respect delta_format for compatibility
 
1507
            revision.delta.show(to_file, self.show_ids, indent=indent,
 
1508
                                short_status=False)
1553
1509
        if revision.diff is not None:
1554
1510
            to_file.write(indent + 'diff:\n')
1555
1511
            to_file.flush()
1618
1574
                to_file.write(indent + offset + '%s\n' % (l,))
1619
1575
 
1620
1576
        if revision.delta is not None:
1621
 
            # Use the standard status output to display changes
1622
 
            from bzrlib.delta import report_delta
1623
 
            report_delta(to_file, revision.delta, 
1624
 
                         short_status=self.delta_format==1, 
1625
 
                         show_ids=self.show_ids, indent=indent + offset)
 
1577
            revision.delta.show(to_file, self.show_ids, indent=indent + offset,
 
1578
                                short_status=self.delta_format==1)
1626
1579
        if revision.diff is not None:
1627
1580
            self.show_diff(self.to_exact_file, revision.diff, '      ')
1628
1581
        to_file.write('\n')
1703
1656
                               self.show_timezone,
1704
1657
                               date_fmt='%Y-%m-%d',
1705
1658
                               show_offset=False)
1706
 
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
 
1659
        committer_str = revision.rev.committer.replace (' <', '  <')
1707
1660
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1708
1661
 
1709
1662
        if revision.delta is not None and revision.delta.has_changed():
2039
1992
        bug_rows = [line.split(' ', 1) for line in bug_lines]
2040
1993
        fixed_bug_urls = [row[0] for row in bug_rows if
2041
1994
                          len(row) > 1 and row[1] == 'fixed']
2042
 
 
 
1995
        
2043
1996
        if fixed_bug_urls:
2044
1997
            return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
2045
1998
    return {}