/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: Martin
  • Date: 2010-04-22 18:36:13 UTC
  • mto: (5177.1.1 integration2)
  • mto: This revision was merged to the branch mainline in revision 5179.
  • Revision ID: gzlist@googlemail.com-20100422183613-gruiwv2xsrjf0nhp
Fix more tests which were failing under -OO that had been missed earlier

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
    diff,
71
71
    errors,
72
72
    foreign,
73
 
    osutils,
74
73
    repository as _mod_repository,
75
74
    revision as _mod_revision,
76
75
    revisionspec,
86
85
    format_date,
87
86
    format_date_with_offset_in_original_timezone,
88
87
    get_terminal_encoding,
 
88
    re_compile_checked,
89
89
    terminal_width,
90
90
    )
91
91
from bzrlib.symbol_versioning import (
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
    }
432
424
        else:
433
425
            specific_files = None
434
426
        s = StringIO()
435
 
        path_encoding = osutils.get_diff_header_encoding()
436
427
        diff.show_diff_trees(tree_1, tree_2, s, specific_files, old_label='',
437
 
            new_label='', path_encoding=path_encoding)
 
428
            new_label='')
438
429
        return s.getvalue()
439
430
 
440
431
    def _create_log_revision_iterator(self):
468
459
            self.branch, self.start_rev_id, self.end_rev_id,
469
460
            rqst.get('direction'),
470
461
            generate_merge_revisions=generate_merge_revisions,
471
 
            delayed_graph_generation=delayed_graph_generation,
472
 
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
 
462
            delayed_graph_generation=delayed_graph_generation)
473
463
 
474
464
        # Apply the other filters
475
465
        return make_log_rev_iterator(self.branch, view_revisions,
484
474
        rqst = self.rqst
485
475
        view_revisions = _calc_view_revisions(
486
476
            self.branch, self.start_rev_id, self.end_rev_id,
487
 
            rqst.get('direction'), generate_merge_revisions=True,
488
 
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
 
477
            rqst.get('direction'), generate_merge_revisions=True)
489
478
        if not isinstance(view_revisions, list):
490
479
            view_revisions = list(view_revisions)
491
480
        view_revisions = _filter_revisions_touching_file_id(self.branch,
496
485
 
497
486
 
498
487
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
499
 
                         generate_merge_revisions,
500
 
                         delayed_graph_generation=False,
501
 
                         exclude_common_ancestry=False,
502
 
                         ):
 
488
    generate_merge_revisions, delayed_graph_generation=False):
503
489
    """Calculate the revisions to view.
504
490
 
505
491
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
506
492
             a list of the same tuples.
507
493
    """
508
 
    if (exclude_common_ancestry and start_rev_id == end_rev_id):
509
 
        raise errors.BzrCommandError(
510
 
            '--exclude-common-ancestry requires two different revisions')
511
494
    if direction not in ('reverse', 'forward'):
512
495
        raise ValueError('invalid direction %r' % direction)
513
496
    br_revno, br_rev_id = branch.last_revision_info()
523
506
    elif not generate_merge_revisions:
524
507
        # If we only want to see linear revisions, we can iterate ...
525
508
        iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
526
 
                                             direction, exclude_common_ancestry)
 
509
                                             direction)
527
510
        if direction == 'forward':
528
511
            iter_revs = reversed(iter_revs)
529
512
    else:
530
513
        iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
531
 
                                            direction, delayed_graph_generation,
532
 
                                            exclude_common_ancestry)
 
514
                                            direction, delayed_graph_generation)
533
515
        if direction == 'forward':
534
516
            iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
535
517
    return iter_revs
545
527
        return [(rev_id, revno_str, 0)]
546
528
 
547
529
 
548
 
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction,
549
 
                             exclude_common_ancestry=False):
550
 
    result = _linear_view_revisions(
551
 
        branch, start_rev_id, end_rev_id,
552
 
        exclude_common_ancestry=exclude_common_ancestry)
 
530
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction):
 
531
    result = _linear_view_revisions(branch, start_rev_id, end_rev_id)
553
532
    # If a start limit was given and it's not obviously an
554
533
    # ancestor of the end limit, check it before outputting anything
555
534
    if direction == 'forward' or (start_rev_id
563
542
 
564
543
 
565
544
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
566
 
                            delayed_graph_generation,
567
 
                            exclude_common_ancestry=False):
 
545
                            delayed_graph_generation):
568
546
    # On large trees, generating the merge graph can take 30-60 seconds
569
547
    # so we delay doing it until a merge is detected, incrementally
570
548
    # returning initial (non-merge) revisions while we can.
576
554
    if delayed_graph_generation:
577
555
        try:
578
556
            for rev_id, revno, depth in  _linear_view_revisions(
579
 
                branch, start_rev_id, end_rev_id, exclude_common_ancestry):
 
557
                branch, start_rev_id, end_rev_id):
580
558
                if _has_merges(branch, rev_id):
581
559
                    # The end_rev_id can be nested down somewhere. We need an
582
560
                    # explicit ancestry check. There is an ambiguity here as we
616
594
    # indented at the end seems slightly nicer in that case.
617
595
    view_revisions = chain(iter(initial_revisions),
618
596
        _graph_view_revisions(branch, start_rev_id, end_rev_id,
619
 
                              rebase_initial_depths=(direction == 'reverse'),
620
 
                              exclude_common_ancestry=exclude_common_ancestry))
 
597
                              rebase_initial_depths=(direction == 'reverse')))
621
598
    return view_revisions
622
599
 
623
600
 
647
624
    return True
648
625
 
649
626
 
650
 
def _linear_view_revisions(branch, start_rev_id, end_rev_id,
651
 
                           exclude_common_ancestry=False):
 
627
def _linear_view_revisions(branch, start_rev_id, end_rev_id):
652
628
    """Calculate a sequence of revisions to view, newest to oldest.
653
629
 
654
630
    :param start_rev_id: the lower revision-id
655
631
    :param end_rev_id: the upper revision-id
656
 
    :param exclude_common_ancestry: Whether the start_rev_id should be part of
657
 
        the iterated revisions.
658
632
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
659
633
    :raises _StartNotLinearAncestor: if a start_rev_id is specified but
660
 
        is not found walking the left-hand history
 
634
      is not found walking the left-hand history
661
635
    """
662
636
    br_revno, br_rev_id = branch.last_revision_info()
663
637
    repo = branch.repository
674
648
            revno = branch.revision_id_to_dotted_revno(revision_id)
675
649
            revno_str = '.'.join(str(n) for n in revno)
676
650
            if not found_start and revision_id == start_rev_id:
677
 
                if not exclude_common_ancestry:
678
 
                    yield revision_id, revno_str, 0
 
651
                yield revision_id, revno_str, 0
679
652
                found_start = True
680
653
                break
681
654
            else:
686
659
 
687
660
 
688
661
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
689
 
                          rebase_initial_depths=True,
690
 
                          exclude_common_ancestry=False):
 
662
                          rebase_initial_depths=True):
691
663
    """Calculate revisions to view including merges, newest to oldest.
692
664
 
693
665
    :param branch: the branch
697
669
      revision is found?
698
670
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
699
671
    """
700
 
    if exclude_common_ancestry:
701
 
        stop_rule = 'with-merges-without-common-ancestry'
702
 
    else:
703
 
        stop_rule = 'with-merges'
704
672
    view_revisions = branch.iter_merge_sorted_revisions(
705
673
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
706
 
        stop_rule=stop_rule)
 
674
        stop_rule="with-merges")
707
675
    if not rebase_initial_depths:
708
676
        for (rev_id, merge_depth, revno, end_of_merge
709
677
             ) in view_revisions:
810
778
    """
811
779
    if search is None:
812
780
        return log_rev_iterator
813
 
    searchRE = re.compile(search, re.IGNORECASE)
 
781
    searchRE = re_compile_checked(search, re.IGNORECASE,
 
782
            'log message filter')
814
783
    return _filter_message_re(searchRE, log_rev_iterator)
815
784
 
816
785
 
1348
1317
 
1349
1318
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1350
1319
                 delta_format=None, levels=None, show_advice=False,
1351
 
                 to_exact_file=None, author_list_handler=None):
 
1320
                 to_exact_file=None):
1352
1321
        """Create a LogFormatter.
1353
1322
 
1354
1323
        :param to_file: the file to output to
1362
1331
          let the log formatter decide.
1363
1332
        :param show_advice: whether to show advice at the end of the
1364
1333
          log or not
1365
 
        :param author_list_handler: callable generating a list of
1366
 
          authors to display for a given revision
1367
1334
        """
1368
1335
        self.to_file = to_file
1369
1336
        # 'exact' stream used to show diff, it should print content 'as is'
1384
1351
        self.levels = levels
1385
1352
        self._show_advice = show_advice
1386
1353
        self._merge_count = 0
1387
 
        self._author_list_handler = author_list_handler
1388
1354
 
1389
1355
    def get_levels(self):
1390
1356
        """Get the number of levels to display or 0 for all."""
1422
1388
        return address
1423
1389
 
1424
1390
    def short_author(self, rev):
1425
 
        return self.authors(rev, 'first', short=True, sep=', ')
1426
 
 
1427
 
    def authors(self, rev, who, short=False, sep=None):
1428
 
        """Generate list of authors, taking --authors option into account.
1429
 
 
1430
 
        The caller has to specify the name of a author list handler,
1431
 
        as provided by the author list registry, using the ``who``
1432
 
        argument.  That name only sets a default, though: when the
1433
 
        user selected a different author list generation using the
1434
 
        ``--authors`` command line switch, as represented by the
1435
 
        ``author_list_handler`` constructor argument, that value takes
1436
 
        precedence.
1437
 
 
1438
 
        :param rev: The revision for which to generate the list of authors.
1439
 
        :param who: Name of the default handler.
1440
 
        :param short: Whether to shorten names to either name or address.
1441
 
        :param sep: What separator to use for automatic concatenation.
1442
 
        """
1443
 
        if self._author_list_handler is not None:
1444
 
            # The user did specify --authors, which overrides the default
1445
 
            author_list_handler = self._author_list_handler
1446
 
        else:
1447
 
            # The user didn't specify --authors, so we use the caller's default
1448
 
            author_list_handler = author_list_registry.get(who)
1449
 
        names = author_list_handler(rev)
1450
 
        if short:
1451
 
            for i in range(len(names)):
1452
 
                name, address = config.parse_username(names[i])
1453
 
                if name:
1454
 
                    names[i] = name
1455
 
                else:
1456
 
                    names[i] = address
1457
 
        if sep is not None:
1458
 
            names = sep.join(names)
1459
 
        return names
 
1391
        name, address = config.parse_username(rev.get_apparent_authors()[0])
 
1392
        if name:
 
1393
            return name
 
1394
        return address
1460
1395
 
1461
1396
    def merge_marker(self, revision):
1462
1397
        """Get the merge marker to include in the output or '' if none."""
1564
1499
        lines.extend(self.custom_properties(revision.rev))
1565
1500
 
1566
1501
        committer = revision.rev.committer
1567
 
        authors = self.authors(revision.rev, 'all')
 
1502
        authors = revision.rev.get_apparent_authors()
1568
1503
        if authors != [committer]:
1569
1504
            lines.append('author: %s' % (", ".join(authors),))
1570
1505
        lines.append('committer: %s' % (committer,))
1744
1679
                               self.show_timezone,
1745
1680
                               date_fmt='%Y-%m-%d',
1746
1681
                               show_offset=False)
1747
 
        committer_str = self.authors(revision.rev, 'first', sep=', ')
1748
 
        committer_str = committer_str.replace(' <', '  <')
 
1682
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
1749
1683
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1750
1684
 
1751
1685
        if revision.delta is not None and revision.delta.has_changed():
1816
1750
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1817
1751
 
1818
1752
 
1819
 
def author_list_all(rev):
1820
 
    return rev.get_apparent_authors()[:]
1821
 
 
1822
 
 
1823
 
def author_list_first(rev):
1824
 
    lst = rev.get_apparent_authors()
1825
 
    try:
1826
 
        return [lst[0]]
1827
 
    except IndexError:
1828
 
        return []
1829
 
 
1830
 
 
1831
 
def author_list_committer(rev):
1832
 
    return [rev.committer]
1833
 
 
1834
 
 
1835
 
author_list_registry = registry.Registry()
1836
 
 
1837
 
author_list_registry.register('all', author_list_all,
1838
 
                              'All authors')
1839
 
 
1840
 
author_list_registry.register('first', author_list_first,
1841
 
                              'The first author')
1842
 
 
1843
 
author_list_registry.register('committer', author_list_committer,
1844
 
                              'The committer')
1845
 
 
1846
 
 
1847
1753
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1848
1754
    # deprecated; for compatibility
1849
1755
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
2000
1906
        lf.log_revision(lr)
2001
1907
 
2002
1908
 
2003
 
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
 
1909
def _get_info_for_log_files(revisionspec_list, file_list):
2004
1910
    """Find file-ids and kinds given a list of files and a revision range.
2005
1911
 
2006
1912
    We search for files at the end of the range. If not found there,
2010
1916
    :param file_list: the list of paths given on the command line;
2011
1917
      the first of these can be a branch location or a file path,
2012
1918
      the remainder must be file paths
2013
 
    :param add_cleanup: When the branch returned is read locked,
2014
 
      an unlock call will be queued to the cleanup.
2015
1919
    :return: (branch, info_list, start_rev_info, end_rev_info) where
2016
1920
      info_list is a list of (relative_path, file_id, kind) tuples where
2017
1921
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2019
1923
    """
2020
1924
    from builtins import _get_revision_range, safe_relpath_files
2021
1925
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2022
 
    add_cleanup(b.lock_read().unlock)
 
1926
    b.lock_read()
2023
1927
    # XXX: It's damn messy converting a list of paths to relative paths when
2024
1928
    # those paths might be deleted ones, they might be on a case-insensitive
2025
1929
    # filesystem and/or they might be in silly locations (like another branch).