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

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
88
88
    re_compile_checked,
89
89
    terminal_width,
90
90
    )
 
91
from bzrlib.symbol_versioning import (
 
92
    deprecated_function,
 
93
    deprecated_in,
 
94
    )
91
95
 
92
96
 
93
97
def find_touching_revisions(branch, file_id):
105
109
    last_path = None
106
110
    revno = 1
107
111
    for revision_id in branch.revision_history():
108
 
        this_inv = branch.repository.get_revision_inventory(revision_id)
 
112
        this_inv = branch.repository.get_inventory(revision_id)
109
113
        if file_id in this_inv:
110
114
            this_ie = this_inv[file_id]
111
115
            this_path = this_inv.id2path(file_id)
216
220
    'direction': 'reverse',
217
221
    'levels': 1,
218
222
    'generate_tags': True,
 
223
    'exclude_common_ancestry': False,
219
224
    '_match_using_deltas': True,
220
225
    }
221
226
 
222
227
 
223
228
def make_log_request_dict(direction='reverse', specific_fileids=None,
224
 
    start_revision=None, end_revision=None, limit=None,
225
 
    message_search=None, levels=1, generate_tags=True, delta_type=None,
226
 
    diff_type=None, _match_using_deltas=True):
 
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
                          ):
227
235
    """Convenience function for making a logging request dictionary.
228
236
 
229
237
    Using this function may make code slightly safer by ensuring
267
275
      algorithm used for matching specific_fileids. This parameter
268
276
      may be removed in the future so bzrlib client code should NOT
269
277
      use it.
 
278
 
 
279
    :param exclude_common_ancestry: Whether -rX..Y should be interpreted as a
 
280
      range operator or as a graph difference.
270
281
    """
271
282
    return {
272
283
        'direction': direction,
279
290
        'generate_tags': generate_tags,
280
291
        'delta_type': delta_type,
281
292
        'diff_type': diff_type,
 
293
        'exclude_common_ancestry': exclude_common_ancestry,
282
294
        # Add 'private' attributes for features that may be deprecated
283
295
        '_match_using_deltas': _match_using_deltas,
284
296
    }
304
316
 
305
317
 
306
318
class Logger(object):
307
 
    """An object the generates, formats and displays a log."""
 
319
    """An object that generates, formats and displays a log."""
308
320
 
309
321
    def __init__(self, branch, rqst):
310
322
        """Create a Logger.
451
463
        generate_merge_revisions = rqst.get('levels') != 1
452
464
        delayed_graph_generation = not rqst.get('specific_fileids') and (
453
465
                rqst.get('limit') or self.start_rev_id or self.end_rev_id)
454
 
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
455
 
            self.end_rev_id, rqst.get('direction'), generate_merge_revisions,
456
 
            delayed_graph_generation=delayed_graph_generation)
 
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'))
457
472
 
458
473
        # Apply the other filters
459
474
        return make_log_rev_iterator(self.branch, view_revisions,
466
481
        # Note that we always generate the merge revisions because
467
482
        # filter_revisions_touching_file_id() requires them ...
468
483
        rqst = self.rqst
469
 
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
470
 
            self.end_rev_id, rqst.get('direction'), True)
 
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'))
471
488
        if not isinstance(view_revisions, list):
472
489
            view_revisions = list(view_revisions)
473
490
        view_revisions = _filter_revisions_touching_file_id(self.branch,
478
495
 
479
496
 
480
497
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
481
 
    generate_merge_revisions, delayed_graph_generation=False):
 
498
                         generate_merge_revisions,
 
499
                         delayed_graph_generation=False,
 
500
                         exclude_common_ancestry=False,
 
501
                         ):
482
502
    """Calculate the revisions to view.
483
503
 
484
504
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
485
505
             a list of the same tuples.
486
506
    """
 
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)
487
512
    br_revno, br_rev_id = branch.last_revision_info()
488
513
    if br_revno == 0:
489
514
        return []
490
515
 
491
 
    # If a single revision is requested, check we can handle it
492
 
    generate_single_revision = (end_rev_id and start_rev_id == end_rev_id and
493
 
        (not generate_merge_revisions or not _has_merges(branch, end_rev_id)))
494
 
    if generate_single_revision:
495
 
        return _generate_one_revision(branch, end_rev_id, br_rev_id, br_revno)
496
 
 
497
 
    # If we only want to see linear revisions, we can iterate ...
498
 
    if not generate_merge_revisions:
499
 
        return _generate_flat_revisions(branch, start_rev_id, end_rev_id,
500
 
            direction)
 
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)
501
528
    else:
502
 
        return _generate_all_revisions(branch, start_rev_id, end_rev_id,
503
 
            direction, delayed_graph_generation)
 
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
504
535
 
505
536
 
506
537
def _generate_one_revision(branch, rev_id, br_rev_id, br_revno):
524
555
        except _StartNotLinearAncestor:
525
556
            raise errors.BzrCommandError('Start revision not found in'
526
557
                ' left-hand history of end revision.')
527
 
    if direction == 'forward':
528
 
        result = reversed(result)
529
558
    return result
530
559
 
531
560
 
532
561
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
533
 
    delayed_graph_generation):
 
562
                            delayed_graph_generation,
 
563
                            exclude_common_ancestry=False):
534
564
    # On large trees, generating the merge graph can take 30-60 seconds
535
565
    # so we delay doing it until a merge is detected, incrementally
536
566
    # 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
537
571
    initial_revisions = []
538
572
    if delayed_graph_generation:
539
573
        try:
540
 
            for rev_id, revno, depth in \
541
 
                _linear_view_revisions(branch, start_rev_id, end_rev_id):
 
574
            for rev_id, revno, depth in  _linear_view_revisions(
 
575
                branch, start_rev_id, end_rev_id):
542
576
                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.
543
592
                    end_rev_id = rev_id
544
593
                    break
545
594
                else:
546
595
                    initial_revisions.append((rev_id, revno, depth))
547
596
            else:
548
597
                # No merged revisions found
549
 
                if direction == 'reverse':
550
 
                    return initial_revisions
551
 
                elif direction == 'forward':
552
 
                    return reversed(initial_revisions)
553
 
                else:
554
 
                    raise ValueError('invalid direction %r' % direction)
 
598
                return initial_revisions
555
599
        except _StartNotLinearAncestor:
556
600
            # A merge was never detected so the lower revision limit can't
557
601
            # be nested down somewhere
558
602
            raise errors.BzrCommandError('Start revision not found in'
559
603
                ' history of end revision.')
560
604
 
 
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
 
561
608
    # A log including nested merges is required. If the direction is reverse,
562
609
    # we rebase the initial merge depths so that the development line is
563
610
    # shown naturally, i.e. just like it is for linear logging. We can easily
565
612
    # indented at the end seems slightly nicer in that case.
566
613
    view_revisions = chain(iter(initial_revisions),
567
614
        _graph_view_revisions(branch, start_rev_id, end_rev_id,
568
 
        rebase_initial_depths=direction == 'reverse'))
569
 
    if direction == 'reverse':
570
 
        return view_revisions
571
 
    elif direction == 'forward':
572
 
        # Forward means oldest first, adjusting for depth.
573
 
        view_revisions = reverse_by_depth(list(view_revisions))
574
 
        return _rebase_merge_depth(view_revisions)
575
 
    else:
576
 
        raise ValueError('invalid direction %r' % direction)
 
615
                              rebase_initial_depths=(direction == 'reverse'),
 
616
                              exclude_common_ancestry=exclude_common_ancestry))
 
617
    return view_revisions
577
618
 
578
619
 
579
620
def _has_merges(branch, rev_id):
597
638
        else:
598
639
            # not obvious
599
640
            return False
 
641
    # if either start or end is not specified then we use either the first or
 
642
    # the last revision and *they* are obvious ancestors.
600
643
    return True
601
644
 
602
645
 
635
678
 
636
679
 
637
680
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
638
 
    rebase_initial_depths=True):
 
681
                          rebase_initial_depths=True,
 
682
                          exclude_common_ancestry=False):
639
683
    """Calculate revisions to view including merges, newest to oldest.
640
684
 
641
685
    :param branch: the branch
645
689
      revision is found?
646
690
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
647
691
    """
 
692
    if exclude_common_ancestry:
 
693
        stop_rule = 'with-merges-without-common-ancestry'
 
694
    else:
 
695
        stop_rule = 'with-merges'
648
696
    view_revisions = branch.iter_merge_sorted_revisions(
649
697
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
650
 
        stop_rule="with-merges")
 
698
        stop_rule=stop_rule)
651
699
    if not rebase_initial_depths:
652
700
        for (rev_id, merge_depth, revno, end_of_merge
653
701
             ) in view_revisions:
664
712
                depth_adjustment = merge_depth
665
713
            if depth_adjustment:
666
714
                if merge_depth < depth_adjustment:
 
715
                    # From now on we reduce the depth adjustement, this can be
 
716
                    # surprising for users. The alternative requires two passes
 
717
                    # which breaks the fast display of the first revision
 
718
                    # though.
667
719
                    depth_adjustment = merge_depth
668
720
                merge_depth -= depth_adjustment
669
721
            yield rev_id, '.'.join(map(str, revno)), merge_depth
670
722
 
671
723
 
 
724
@deprecated_function(deprecated_in((2, 2, 0)))
672
725
def calculate_view_revisions(branch, start_revision, end_revision, direction,
673
726
        specific_fileid, generate_merge_revisions):
674
727
    """Calculate the revisions to view.
676
729
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
677
730
             a list of the same tuples.
678
731
    """
679
 
    # This method is no longer called by the main code path.
680
 
    # It is retained for API compatibility and may be deprecated
681
 
    # soon. IGC 20090116
682
732
    start_rev_id, end_rev_id = _get_revision_limits(branch, start_revision,
683
733
        end_revision)
684
734
    view_revisions = list(_calc_view_revisions(branch, start_rev_id, end_rev_id,
1034
1084
    return mainline_revs, rev_nos, start_rev_id, end_rev_id
1035
1085
 
1036
1086
 
 
1087
@deprecated_function(deprecated_in((2, 2, 0)))
1037
1088
def _filter_revision_range(view_revisions, start_rev_id, end_rev_id):
1038
1089
    """Filter view_revisions based on revision ranges.
1039
1090
 
1048
1099
 
1049
1100
    :return: The filtered view_revisions.
1050
1101
    """
1051
 
    # This method is no longer called by the main code path.
1052
 
    # It may be removed soon. IGC 20090127
1053
1102
    if start_rev_id or end_rev_id:
1054
1103
        revision_ids = [r for r, n, d in view_revisions]
1055
1104
        if start_rev_id:
1161
1210
    return result
1162
1211
 
1163
1212
 
 
1213
@deprecated_function(deprecated_in((2, 2, 0)))
1164
1214
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
1165
1215
                       include_merges=True):
1166
1216
    """Produce an iterator of revisions to show
1167
1217
    :return: an iterator of (revision_id, revno, merge_depth)
1168
1218
    (if there is no revno for a revision, None is supplied)
1169
1219
    """
1170
 
    # This method is no longer called by the main code path.
1171
 
    # It is retained for API compatibility and may be deprecated
1172
 
    # soon. IGC 20090127
1173
1220
    if not include_merges:
1174
1221
        revision_ids = mainline_revs[1:]
1175
1222
        if direction == 'reverse':
1293
1340
    preferred_levels = 0
1294
1341
 
1295
1342
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1296
 
            delta_format=None, levels=None, show_advice=False,
1297
 
            to_exact_file=None):
 
1343
                 delta_format=None, levels=None, show_advice=False,
 
1344
                 to_exact_file=None):
1298
1345
        """Create a LogFormatter.
1299
1346
 
1300
1347
        :param to_file: the file to output to
1405
1452
        """
1406
1453
        # Revision comes directly from a foreign repository
1407
1454
        if isinstance(rev, foreign.ForeignRevision):
1408
 
            return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
 
1455
            return self._format_properties(
 
1456
                rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
1409
1457
 
1410
1458
        # Imported foreign revision revision ids always contain :
1411
1459
        if not ":" in rev.revision_id:
1498
1546
        to_file = self.to_file
1499
1547
        to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1500
1548
        if revision.delta is not None:
1501
 
            # We don't respect delta_format for compatibility
1502
 
            revision.delta.show(to_file, self.show_ids, indent=indent,
1503
 
                                short_status=False)
 
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)
1504
1553
        if revision.diff is not None:
1505
1554
            to_file.write(indent + 'diff:\n')
1506
1555
            to_file.flush()
1569
1618
                to_file.write(indent + offset + '%s\n' % (l,))
1570
1619
 
1571
1620
        if revision.delta is not None:
1572
 
            revision.delta.show(to_file, self.show_ids, indent=indent + offset,
1573
 
                                short_status=self.delta_format==1)
 
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)
1574
1626
        if revision.diff is not None:
1575
1627
            self.show_diff(self.to_exact_file, revision.diff, '      ')
1576
1628
        to_file.write('\n')
1651
1703
                               self.show_timezone,
1652
1704
                               date_fmt='%Y-%m-%d',
1653
1705
                               show_offset=False)
1654
 
        committer_str = revision.rev.committer.replace (' <', '  <')
 
1706
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
1655
1707
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1656
1708
 
1657
1709
        if revision.delta is not None and revision.delta.has_changed():
1987
2039
        bug_rows = [line.split(' ', 1) for line in bug_lines]
1988
2040
        fixed_bug_urls = [row[0] for row in bug_rows if
1989
2041
                          len(row) > 1 and row[1] == 'fixed']
1990
 
        
 
2042
 
1991
2043
        if fixed_bug_urls:
1992
2044
            return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
1993
2045
    return {}