/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: Marius Kruger
  • Date: 2009-10-31 23:07:35 UTC
  • mfrom: (4780 +trunk)
  • mto: (4867.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4868.
  • Revision ID: marius.kruger@enerweb.co.za-20091031230735-4hyr0u14nci0xu7b
merge with bzr.dev

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
83
83
    )
84
84
from bzrlib.osutils import (
85
85
    format_date,
86
 
    format_date_with_offset_in_original_timezone,
87
86
    get_terminal_encoding,
88
87
    re_compile_checked,
89
88
    terminal_width,
90
89
    )
91
 
from bzrlib.symbol_versioning import (
92
 
    deprecated_function,
93
 
    deprecated_in,
94
 
    )
95
90
 
96
91
 
97
92
def find_touching_revisions(branch, file_id):
109
104
    last_path = None
110
105
    revno = 1
111
106
    for revision_id in branch.revision_history():
112
 
        this_inv = branch.repository.get_inventory(revision_id)
 
107
        this_inv = branch.repository.get_revision_inventory(revision_id)
113
108
        if file_id in this_inv:
114
109
            this_ie = this_inv[file_id]
115
110
            this_path = this_inv.id2path(file_id)
220
215
    'direction': 'reverse',
221
216
    'levels': 1,
222
217
    'generate_tags': True,
223
 
    'exclude_common_ancestry': False,
224
218
    '_match_using_deltas': True,
225
219
    }
226
220
 
227
221
 
228
222
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
 
                          ):
 
223
    start_revision=None, end_revision=None, limit=None,
 
224
    message_search=None, levels=1, generate_tags=True, delta_type=None,
 
225
    diff_type=None, _match_using_deltas=True):
235
226
    """Convenience function for making a logging request dictionary.
236
227
 
237
228
    Using this function may make code slightly safer by ensuring
275
266
      algorithm used for matching specific_fileids. This parameter
276
267
      may be removed in the future so bzrlib client code should NOT
277
268
      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
269
    """
282
270
    return {
283
271
        'direction': direction,
290
278
        'generate_tags': generate_tags,
291
279
        'delta_type': delta_type,
292
280
        'diff_type': diff_type,
293
 
        'exclude_common_ancestry': exclude_common_ancestry,
294
281
        # Add 'private' attributes for features that may be deprecated
295
282
        '_match_using_deltas': _match_using_deltas,
296
283
    }
316
303
 
317
304
 
318
305
class Logger(object):
319
 
    """An object that generates, formats and displays a log."""
 
306
    """An object the generates, formats and displays a log."""
320
307
 
321
308
    def __init__(self, branch, rqst):
322
309
        """Create a Logger.
397
384
        :return: An iterator yielding LogRevision objects.
398
385
        """
399
386
        rqst = self.rqst
400
 
        levels = rqst.get('levels')
401
 
        limit = rqst.get('limit')
402
 
        diff_type = rqst.get('diff_type')
403
387
        log_count = 0
404
388
        revision_iterator = self._create_log_revision_iterator()
405
389
        for revs in revision_iterator:
406
390
            for (rev_id, revno, merge_depth), rev, delta in revs:
407
391
                # 0 levels means show everything; merge_depth counts from 0
 
392
                levels = rqst.get('levels')
408
393
                if levels != 0 and merge_depth >= levels:
409
394
                    continue
410
 
                if diff_type is None:
411
 
                    diff = None
412
 
                else:
413
 
                    diff = self._format_diff(rev, rev_id, diff_type)
 
395
                diff = self._format_diff(rev, rev_id)
414
396
                yield LogRevision(rev, revno, merge_depth, delta,
415
397
                    self.rev_tag_dict.get(rev_id), diff)
 
398
                limit = rqst.get('limit')
416
399
                if limit:
417
400
                    log_count += 1
418
401
                    if log_count >= limit:
419
402
                        return
 
403
                # As per Bug #325618 we don't want to show parent revisions
 
404
                # outside of the specified range.
 
405
                # So we need to filter the revisions here again since
 
406
                # the lower levels also return the revision parents,
 
407
                # which is needed for filtering on file_ids.
 
408
                if rqst.get('direction') == 'forward':
 
409
                    if self.end_rev_id == rev_id:
 
410
                        return
 
411
                else:
 
412
                    if self.start_rev_id == rev_id:
 
413
                        return
420
414
 
421
 
    def _format_diff(self, rev, rev_id, diff_type):
 
415
    def _format_diff(self, rev, rev_id):
 
416
        diff_type = self.rqst.get('diff_type')
 
417
        if diff_type is None:
 
418
            return None
422
419
        repo = self.branch.repository
423
420
        if len(rev.parent_ids) == 0:
424
421
            ancestor_id = _mod_revision.NULL_REVISION
463
460
        generate_merge_revisions = rqst.get('levels') != 1
464
461
        delayed_graph_generation = not rqst.get('specific_fileids') and (
465
462
                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'))
 
463
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
 
464
            self.end_rev_id, rqst.get('direction'), generate_merge_revisions,
 
465
            delayed_graph_generation=delayed_graph_generation)
472
466
 
473
467
        # Apply the other filters
474
468
        return make_log_rev_iterator(self.branch, view_revisions,
481
475
        # Note that we always generate the merge revisions because
482
476
        # filter_revisions_touching_file_id() requires them ...
483
477
        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'))
 
478
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
 
479
            self.end_rev_id, rqst.get('direction'), True)
488
480
        if not isinstance(view_revisions, list):
489
481
            view_revisions = list(view_revisions)
490
482
        view_revisions = _filter_revisions_touching_file_id(self.branch,
495
487
 
496
488
 
497
489
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
 
                         ):
 
490
    generate_merge_revisions, delayed_graph_generation=False):
502
491
    """Calculate the revisions to view.
503
492
 
504
493
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
505
494
             a list of the same tuples.
506
495
    """
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
496
    br_revno, br_rev_id = branch.last_revision_info()
513
497
    if br_revno == 0:
514
498
        return []
515
499
 
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)
 
500
    # If a single revision is requested, check we can handle it
 
501
    generate_single_revision = (end_rev_id and start_rev_id == end_rev_id and
 
502
        (not generate_merge_revisions or not _has_merges(branch, end_rev_id)))
 
503
    if generate_single_revision:
 
504
        return _generate_one_revision(branch, end_rev_id, br_rev_id, br_revno)
 
505
 
 
506
    # If we only want to see linear revisions, we can iterate ...
 
507
    if not generate_merge_revisions:
 
508
        return _generate_flat_revisions(branch, start_rev_id, end_rev_id,
 
509
            direction)
528
510
    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
 
511
        return _generate_all_revisions(branch, start_rev_id, end_rev_id,
 
512
            direction, delayed_graph_generation)
535
513
 
536
514
 
537
515
def _generate_one_revision(branch, rev_id, br_rev_id, br_revno):
555
533
        except _StartNotLinearAncestor:
556
534
            raise errors.BzrCommandError('Start revision not found in'
557
535
                ' left-hand history of end revision.')
 
536
    if direction == 'forward':
 
537
        result = reversed(result)
558
538
    return result
559
539
 
560
540
 
561
541
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
562
 
                            delayed_graph_generation,
563
 
                            exclude_common_ancestry=False):
 
542
    delayed_graph_generation):
564
543
    # On large trees, generating the merge graph can take 30-60 seconds
565
544
    # so we delay doing it until a merge is detected, incrementally
566
545
    # 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
546
    initial_revisions = []
572
547
    if delayed_graph_generation:
573
548
        try:
574
 
            for rev_id, revno, depth in  _linear_view_revisions(
575
 
                branch, start_rev_id, end_rev_id):
 
549
            for rev_id, revno, depth in \
 
550
                _linear_view_revisions(branch, start_rev_id, end_rev_id):
576
551
                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
552
                    end_rev_id = rev_id
593
553
                    break
594
554
                else:
595
555
                    initial_revisions.append((rev_id, revno, depth))
596
556
            else:
597
557
                # No merged revisions found
598
 
                return initial_revisions
 
558
                if direction == 'reverse':
 
559
                    return initial_revisions
 
560
                elif direction == 'forward':
 
561
                    return reversed(initial_revisions)
 
562
                else:
 
563
                    raise ValueError('invalid direction %r' % direction)
599
564
        except _StartNotLinearAncestor:
600
565
            # A merge was never detected so the lower revision limit can't
601
566
            # be nested down somewhere
602
567
            raise errors.BzrCommandError('Start revision not found in'
603
568
                ' history of end revision.')
604
569
 
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
570
    # A log including nested merges is required. If the direction is reverse,
609
571
    # we rebase the initial merge depths so that the development line is
610
572
    # shown naturally, i.e. just like it is for linear logging. We can easily
612
574
    # indented at the end seems slightly nicer in that case.
613
575
    view_revisions = chain(iter(initial_revisions),
614
576
        _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
 
577
        rebase_initial_depths=direction == 'reverse'))
 
578
    if direction == 'reverse':
 
579
        return view_revisions
 
580
    elif direction == 'forward':
 
581
        # Forward means oldest first, adjusting for depth.
 
582
        view_revisions = reverse_by_depth(list(view_revisions))
 
583
        return _rebase_merge_depth(view_revisions)
 
584
    else:
 
585
        raise ValueError('invalid direction %r' % direction)
618
586
 
619
587
 
620
588
def _has_merges(branch, rev_id):
638
606
        else:
639
607
            # not obvious
640
608
            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.
643
609
    return True
644
610
 
645
611
 
678
644
 
679
645
 
680
646
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
681
 
                          rebase_initial_depths=True,
682
 
                          exclude_common_ancestry=False):
 
647
    rebase_initial_depths=True):
683
648
    """Calculate revisions to view including merges, newest to oldest.
684
649
 
685
650
    :param branch: the branch
689
654
      revision is found?
690
655
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
691
656
    """
692
 
    if exclude_common_ancestry:
693
 
        stop_rule = 'with-merges-without-common-ancestry'
694
 
    else:
695
 
        stop_rule = 'with-merges'
696
657
    view_revisions = branch.iter_merge_sorted_revisions(
697
658
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
698
 
        stop_rule=stop_rule)
 
659
        stop_rule="with-merges")
699
660
    if not rebase_initial_depths:
700
661
        for (rev_id, merge_depth, revno, end_of_merge
701
662
             ) in view_revisions:
712
673
                depth_adjustment = merge_depth
713
674
            if depth_adjustment:
714
675
                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.
719
676
                    depth_adjustment = merge_depth
720
677
                merge_depth -= depth_adjustment
721
678
            yield rev_id, '.'.join(map(str, revno)), merge_depth
722
679
 
723
680
 
724
 
@deprecated_function(deprecated_in((2, 2, 0)))
725
681
def calculate_view_revisions(branch, start_revision, end_revision, direction,
726
682
        specific_fileid, generate_merge_revisions):
727
683
    """Calculate the revisions to view.
729
685
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
730
686
             a list of the same tuples.
731
687
    """
 
688
    # This method is no longer called by the main code path.
 
689
    # It is retained for API compatibility and may be deprecated
 
690
    # soon. IGC 20090116
732
691
    start_rev_id, end_rev_id = _get_revision_limits(branch, start_revision,
733
692
        end_revision)
734
693
    view_revisions = list(_calc_view_revisions(branch, start_rev_id, end_rev_id,
1084
1043
    return mainline_revs, rev_nos, start_rev_id, end_rev_id
1085
1044
 
1086
1045
 
1087
 
@deprecated_function(deprecated_in((2, 2, 0)))
1088
1046
def _filter_revision_range(view_revisions, start_rev_id, end_rev_id):
1089
1047
    """Filter view_revisions based on revision ranges.
1090
1048
 
1099
1057
 
1100
1058
    :return: The filtered view_revisions.
1101
1059
    """
 
1060
    # This method is no longer called by the main code path.
 
1061
    # It may be removed soon. IGC 20090127
1102
1062
    if start_rev_id or end_rev_id:
1103
1063
        revision_ids = [r for r, n, d in view_revisions]
1104
1064
        if start_rev_id:
1210
1170
    return result
1211
1171
 
1212
1172
 
1213
 
@deprecated_function(deprecated_in((2, 2, 0)))
1214
1173
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
1215
1174
                       include_merges=True):
1216
1175
    """Produce an iterator of revisions to show
1217
1176
    :return: an iterator of (revision_id, revno, merge_depth)
1218
1177
    (if there is no revno for a revision, None is supplied)
1219
1178
    """
 
1179
    # This method is no longer called by the main code path.
 
1180
    # It is retained for API compatibility and may be deprecated
 
1181
    # soon. IGC 20090127
1220
1182
    if not include_merges:
1221
1183
        revision_ids = mainline_revs[1:]
1222
1184
        if direction == 'reverse':
1340
1302
    preferred_levels = 0
1341
1303
 
1342
1304
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
 
                 delta_format=None, levels=None, show_advice=False,
1344
 
                 to_exact_file=None):
 
1305
                 delta_format=None, levels=None, show_advice=False):
1345
1306
        """Create a LogFormatter.
1346
1307
 
1347
1308
        :param to_file: the file to output to
1348
 
        :param to_exact_file: if set, gives an output stream to which 
1349
 
             non-Unicode diffs are written.
1350
1309
        :param show_ids: if True, revision-ids are to be displayed
1351
1310
        :param show_timezone: the timezone to use
1352
1311
        :param delta_format: the level of delta information to display
1359
1318
        self.to_file = to_file
1360
1319
        # 'exact' stream used to show diff, it should print content 'as is'
1361
1320
        # and should not try to decode/encode it to unicode to avoid bug #328007
1362
 
        if to_exact_file is not None:
1363
 
            self.to_exact_file = to_exact_file
1364
 
        else:
1365
 
            # XXX: somewhat hacky; this assumes it's a codec writer; it's better
1366
 
            # for code that expects to get diffs to pass in the exact file
1367
 
            # stream
1368
 
            self.to_exact_file = getattr(to_file, 'stream', to_file)
 
1321
        self.to_exact_file = getattr(to_file, 'stream', to_file)
1369
1322
        self.show_ids = show_ids
1370
1323
        self.show_timezone = show_timezone
1371
1324
        if delta_format is None:
1425
1378
        else:
1426
1379
            return ''
1427
1380
 
1428
 
    def show_properties(self, revision, indent):
1429
 
        """Displays the custom properties returned by each registered handler.
1430
 
 
1431
 
        If a registered handler raises an error it is propagated.
1432
 
        """
1433
 
        for line in self.custom_properties(revision):
1434
 
            self.to_file.write("%s%s\n" % (indent, line))
1435
 
 
1436
 
    def custom_properties(self, revision):
1437
 
        """Format the custom properties returned by each registered handler.
1438
 
 
1439
 
        If a registered handler raises an error it is propagated.
1440
 
 
1441
 
        :return: a list of formatted lines (excluding trailing newlines)
1442
 
        """
1443
 
        lines = self._foreign_info_properties(revision)
1444
 
        for key, handler in properties_handler_registry.iteritems():
1445
 
            lines.extend(self._format_properties(handler(revision)))
1446
 
        return lines
1447
 
 
1448
 
    def _foreign_info_properties(self, rev):
 
1381
    def show_foreign_info(self, rev, indent):
1449
1382
        """Custom log displayer for foreign revision identifiers.
1450
1383
 
1451
1384
        :param rev: Revision object.
1452
1385
        """
1453
1386
        # Revision comes directly from a foreign repository
1454
1387
        if isinstance(rev, foreign.ForeignRevision):
1455
 
            return self._format_properties(
1456
 
                rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
 
1388
            self._write_properties(indent, rev.mapping.vcs.show_foreign_revid(
 
1389
                rev.foreign_revid))
 
1390
            return
1457
1391
 
1458
1392
        # Imported foreign revision revision ids always contain :
1459
1393
        if not ":" in rev.revision_id:
1460
 
            return []
 
1394
            return
1461
1395
 
1462
1396
        # Revision was once imported from a foreign repository
1463
1397
        try:
1464
1398
            foreign_revid, mapping = \
1465
1399
                foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
1466
1400
        except errors.InvalidRevisionId:
1467
 
            return []
 
1401
            return
1468
1402
 
1469
 
        return self._format_properties(
 
1403
        self._write_properties(indent, 
1470
1404
            mapping.vcs.show_foreign_revid(foreign_revid))
1471
1405
 
1472
 
    def _format_properties(self, properties):
1473
 
        lines = []
 
1406
    def show_properties(self, revision, indent):
 
1407
        """Displays the custom properties returned by each registered handler.
 
1408
 
 
1409
        If a registered handler raises an error it is propagated.
 
1410
        """
 
1411
        for key, handler in properties_handler_registry.iteritems():
 
1412
            self._write_properties(indent, handler(revision))
 
1413
 
 
1414
    def _write_properties(self, indent, properties):
1474
1415
        for key, value in properties.items():
1475
 
            lines.append(key + ': ' + value)
1476
 
        return lines
 
1416
            self.to_file.write(indent + key + ': ' + value + '\n')
1477
1417
 
1478
1418
    def show_diff(self, to_file, diff, indent):
1479
1419
        for l in diff.rstrip().split('\n'):
1480
1420
            to_file.write(indent + '%s\n' % (l,))
1481
1421
 
1482
1422
 
1483
 
# Separator between revisions in long format
1484
 
_LONG_SEP = '-' * 60
1485
 
 
1486
 
 
1487
1423
class LongLogFormatter(LogFormatter):
1488
1424
 
1489
1425
    supports_merge_revisions = True
1492
1428
    supports_tags = True
1493
1429
    supports_diff = True
1494
1430
 
1495
 
    def __init__(self, *args, **kwargs):
1496
 
        super(LongLogFormatter, self).__init__(*args, **kwargs)
1497
 
        if self.show_timezone == 'original':
1498
 
            self.date_string = self._date_string_original_timezone
1499
 
        else:
1500
 
            self.date_string = self._date_string_with_timezone
1501
 
 
1502
 
    def _date_string_with_timezone(self, rev):
1503
 
        return format_date(rev.timestamp, rev.timezone or 0,
1504
 
                           self.show_timezone)
1505
 
 
1506
 
    def _date_string_original_timezone(self, rev):
1507
 
        return format_date_with_offset_in_original_timezone(rev.timestamp,
1508
 
            rev.timezone or 0)
1509
 
 
1510
1431
    def log_revision(self, revision):
1511
1432
        """Log a revision, either merged or not."""
1512
1433
        indent = '    ' * revision.merge_depth
1513
 
        lines = [_LONG_SEP]
 
1434
        to_file = self.to_file
 
1435
        to_file.write(indent + '-' * 60 + '\n')
1514
1436
        if revision.revno is not None:
1515
 
            lines.append('revno: %s%s' % (revision.revno,
 
1437
            to_file.write(indent + 'revno: %s%s\n' % (revision.revno,
1516
1438
                self.merge_marker(revision)))
1517
1439
        if revision.tags:
1518
 
            lines.append('tags: %s' % (', '.join(revision.tags)))
 
1440
            to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
1519
1441
        if self.show_ids:
1520
 
            lines.append('revision-id: %s' % (revision.rev.revision_id,))
 
1442
            to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
 
1443
            to_file.write('\n')
1521
1444
            for parent_id in revision.rev.parent_ids:
1522
 
                lines.append('parent: %s' % (parent_id,))
1523
 
        lines.extend(self.custom_properties(revision.rev))
 
1445
                to_file.write(indent + 'parent: %s\n' % (parent_id,))
 
1446
        self.show_foreign_info(revision.rev, indent)
 
1447
        self.show_properties(revision.rev, indent)
1524
1448
 
1525
1449
        committer = revision.rev.committer
1526
1450
        authors = revision.rev.get_apparent_authors()
1527
1451
        if authors != [committer]:
1528
 
            lines.append('author: %s' % (", ".join(authors),))
1529
 
        lines.append('committer: %s' % (committer,))
 
1452
            to_file.write(indent + 'author: %s\n' % (", ".join(authors),))
 
1453
        to_file.write(indent + 'committer: %s\n' % (committer,))
1530
1454
 
1531
1455
        branch_nick = revision.rev.properties.get('branch-nick', None)
1532
1456
        if branch_nick is not None:
1533
 
            lines.append('branch nick: %s' % (branch_nick,))
1534
 
 
1535
 
        lines.append('timestamp: %s' % (self.date_string(revision.rev),))
1536
 
 
1537
 
        lines.append('message:')
 
1457
            to_file.write(indent + 'branch nick: %s\n' % (branch_nick,))
 
1458
 
 
1459
        date_str = format_date(revision.rev.timestamp,
 
1460
                               revision.rev.timezone or 0,
 
1461
                               self.show_timezone)
 
1462
        to_file.write(indent + 'timestamp: %s\n' % (date_str,))
 
1463
 
 
1464
        to_file.write(indent + 'message:\n')
1538
1465
        if not revision.rev.message:
1539
 
            lines.append('  (no message)')
 
1466
            to_file.write(indent + '  (no message)\n')
1540
1467
        else:
1541
1468
            message = revision.rev.message.rstrip('\r\n')
1542
1469
            for l in message.split('\n'):
1543
 
                lines.append('  %s' % (l,))
1544
 
 
1545
 
        # Dump the output, appending the delta and diff if requested
1546
 
        to_file = self.to_file
1547
 
        to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
 
1470
                to_file.write(indent + '  %s\n' % (l,))
1548
1471
        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)
 
1472
            # We don't respect delta_format for compatibility
 
1473
            revision.delta.show(to_file, self.show_ids, indent=indent,
 
1474
                                short_status=False)
1553
1475
        if revision.diff is not None:
1554
1476
            to_file.write(indent + 'diff:\n')
1555
 
            to_file.flush()
1556
1477
            # Note: we explicitly don't indent the diff (relative to the
1557
1478
            # revision information) so that the output can be fed to patch -p0
1558
1479
            self.show_diff(self.to_exact_file, revision.diff, indent)
1559
 
            self.to_exact_file.flush()
1560
1480
 
1561
1481
    def get_advice_separator(self):
1562
1482
        """Get the text separating the log from the closing advice."""
1606
1526
                            self.show_timezone, date_fmt="%Y-%m-%d",
1607
1527
                            show_offset=False),
1608
1528
                tags, self.merge_marker(revision)))
 
1529
        self.show_foreign_info(revision.rev, indent+offset)
1609
1530
        self.show_properties(revision.rev, indent+offset)
1610
1531
        if self.show_ids:
1611
1532
            to_file.write(indent + offset + 'revision-id:%s\n'
1618
1539
                to_file.write(indent + offset + '%s\n' % (l,))
1619
1540
 
1620
1541
        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)
 
1542
            revision.delta.show(to_file, self.show_ids, indent=indent + offset,
 
1543
                                short_status=self.delta_format==1)
1626
1544
        if revision.diff is not None:
1627
1545
            self.show_diff(self.to_exact_file, revision.diff, '      ')
1628
1546
        to_file.write('\n')
1636
1554
 
1637
1555
    def __init__(self, *args, **kwargs):
1638
1556
        super(LineLogFormatter, self).__init__(*args, **kwargs)
1639
 
        width = terminal_width()
1640
 
        if width is not None:
1641
 
            # we need one extra space for terminals that wrap on last char
1642
 
            width = width - 1
1643
 
        self._max_chars = width
 
1557
        self._max_chars = terminal_width() - 1
1644
1558
 
1645
1559
    def truncate(self, str, max_len):
1646
 
        if max_len is None or len(str) <= max_len:
 
1560
        if len(str) <= max_len:
1647
1561
            return str
1648
 
        return str[:max_len-3] + '...'
 
1562
        return str[:max_len-3]+'...'
1649
1563
 
1650
1564
    def date_string(self, rev):
1651
1565
        return format_date(rev.timestamp, rev.timezone or 0,
1703
1617
                               self.show_timezone,
1704
1618
                               date_fmt='%Y-%m-%d',
1705
1619
                               show_offset=False)
1706
 
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
 
1620
        committer_str = revision.rev.committer.replace (' <', '  <')
1707
1621
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1708
1622
 
1709
1623
        if revision.delta is not None and revision.delta.has_changed():
2032
1946
 
2033
1947
properties_handler_registry = registry.Registry()
2034
1948
 
2035
 
# Use the properties handlers to print out bug information if available
2036
 
def _bugs_properties_handler(revision):
2037
 
    if revision.properties.has_key('bugs'):
2038
 
        bug_lines = revision.properties['bugs'].split('\n')
2039
 
        bug_rows = [line.split(' ', 1) for line in bug_lines]
2040
 
        fixed_bug_urls = [row[0] for row in bug_rows if
2041
 
                          len(row) > 1 and row[1] == 'fixed']
2042
 
 
2043
 
        if fixed_bug_urls:
2044
 
            return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
2045
 
    return {}
2046
 
 
2047
 
properties_handler_registry.register('bugs_properties_handler',
2048
 
                                     _bugs_properties_handler)
2049
 
 
2050
1949
 
2051
1950
# adapters which revision ids to log are filtered. When log is called, the
2052
1951
# log_rev_iterator is adapted through each of these factory methods.