/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:
73
73
    repository as _mod_repository,
74
74
    revision as _mod_revision,
75
75
    revisionspec,
 
76
    trace,
76
77
    tsort,
77
78
    )
78
79
""")
83
84
from bzrlib.osutils import (
84
85
    format_date,
85
86
    format_date_with_offset_in_original_timezone,
86
 
    get_diff_header_encoding,
87
87
    get_terminal_encoding,
 
88
    re_compile_checked,
88
89
    terminal_width,
89
90
    )
90
91
from bzrlib.symbol_versioning import (
431
432
        else:
432
433
            specific_files = None
433
434
        s = StringIO()
434
 
        path_encoding = get_diff_header_encoding()
435
435
        diff.show_diff_trees(tree_1, tree_2, s, specific_files, old_label='',
436
 
            new_label='', path_encoding=path_encoding)
 
436
            new_label='')
437
437
        return s.getvalue()
438
438
 
439
439
    def _create_log_revision_iterator(self):
522
522
    elif not generate_merge_revisions:
523
523
        # If we only want to see linear revisions, we can iterate ...
524
524
        iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
525
 
                                             direction, exclude_common_ancestry)
 
525
                                             direction)
526
526
        if direction == 'forward':
527
527
            iter_revs = reversed(iter_revs)
528
528
    else:
544
544
        return [(rev_id, revno_str, 0)]
545
545
 
546
546
 
547
 
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction,
548
 
                             exclude_common_ancestry=False):
549
 
    result = _linear_view_revisions(
550
 
        branch, start_rev_id, end_rev_id,
551
 
        exclude_common_ancestry=exclude_common_ancestry)
 
547
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction):
 
548
    result = _linear_view_revisions(branch, start_rev_id, end_rev_id)
552
549
    # If a start limit was given and it's not obviously an
553
550
    # ancestor of the end limit, check it before outputting anything
554
551
    if direction == 'forward' or (start_rev_id
575
572
    if delayed_graph_generation:
576
573
        try:
577
574
            for rev_id, revno, depth in  _linear_view_revisions(
578
 
                branch, start_rev_id, end_rev_id, exclude_common_ancestry):
 
575
                branch, start_rev_id, end_rev_id):
579
576
                if _has_merges(branch, rev_id):
580
577
                    # The end_rev_id can be nested down somewhere. We need an
581
578
                    # explicit ancestry check. There is an ambiguity here as we
646
643
    return True
647
644
 
648
645
 
649
 
def _linear_view_revisions(branch, start_rev_id, end_rev_id,
650
 
                           exclude_common_ancestry=False):
 
646
def _linear_view_revisions(branch, start_rev_id, end_rev_id):
651
647
    """Calculate a sequence of revisions to view, newest to oldest.
652
648
 
653
649
    :param start_rev_id: the lower revision-id
654
650
    :param end_rev_id: the upper revision-id
655
 
    :param exclude_common_ancestry: Whether the start_rev_id should be part of
656
 
        the iterated revisions.
657
651
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
658
652
    :raises _StartNotLinearAncestor: if a start_rev_id is specified but
659
 
        is not found walking the left-hand history
 
653
      is not found walking the left-hand history
660
654
    """
661
655
    br_revno, br_rev_id = branch.last_revision_info()
662
656
    repo = branch.repository
673
667
            revno = branch.revision_id_to_dotted_revno(revision_id)
674
668
            revno_str = '.'.join(str(n) for n in revno)
675
669
            if not found_start and revision_id == start_rev_id:
676
 
                if not exclude_common_ancestry:
677
 
                    yield revision_id, revno_str, 0
 
670
                yield revision_id, revno_str, 0
678
671
                found_start = True
679
672
                break
680
673
            else:
809
802
    """
810
803
    if search is None:
811
804
        return log_rev_iterator
812
 
    searchRE = re.compile(search, re.IGNORECASE)
 
805
    searchRE = re_compile_checked(search, re.IGNORECASE,
 
806
            'log message filter')
813
807
    return _filter_message_re(searchRE, log_rev_iterator)
814
808
 
815
809
 
1347
1341
 
1348
1342
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1349
1343
                 delta_format=None, levels=None, show_advice=False,
1350
 
                 to_exact_file=None, author_list_handler=None):
 
1344
                 to_exact_file=None):
1351
1345
        """Create a LogFormatter.
1352
1346
 
1353
1347
        :param to_file: the file to output to
1361
1355
          let the log formatter decide.
1362
1356
        :param show_advice: whether to show advice at the end of the
1363
1357
          log or not
1364
 
        :param author_list_handler: callable generating a list of
1365
 
          authors to display for a given revision
1366
1358
        """
1367
1359
        self.to_file = to_file
1368
1360
        # 'exact' stream used to show diff, it should print content 'as is'
1383
1375
        self.levels = levels
1384
1376
        self._show_advice = show_advice
1385
1377
        self._merge_count = 0
1386
 
        self._author_list_handler = author_list_handler
1387
1378
 
1388
1379
    def get_levels(self):
1389
1380
        """Get the number of levels to display or 0 for all."""
1421
1412
        return address
1422
1413
 
1423
1414
    def short_author(self, rev):
1424
 
        return self.authors(rev, 'first', short=True, sep=', ')
1425
 
 
1426
 
    def authors(self, rev, who, short=False, sep=None):
1427
 
        """Generate list of authors, taking --authors option into account.
1428
 
 
1429
 
        The caller has to specify the name of a author list handler,
1430
 
        as provided by the author list registry, using the ``who``
1431
 
        argument.  That name only sets a default, though: when the
1432
 
        user selected a different author list generation using the
1433
 
        ``--authors`` command line switch, as represented by the
1434
 
        ``author_list_handler`` constructor argument, that value takes
1435
 
        precedence.
1436
 
 
1437
 
        :param rev: The revision for which to generate the list of authors.
1438
 
        :param who: Name of the default handler.
1439
 
        :param short: Whether to shorten names to either name or address.
1440
 
        :param sep: What separator to use for automatic concatenation.
1441
 
        """
1442
 
        if self._author_list_handler is not None:
1443
 
            # The user did specify --authors, which overrides the default
1444
 
            author_list_handler = self._author_list_handler
1445
 
        else:
1446
 
            # The user didn't specify --authors, so we use the caller's default
1447
 
            author_list_handler = author_list_registry.get(who)
1448
 
        names = author_list_handler(rev)
1449
 
        if short:
1450
 
            for i in range(len(names)):
1451
 
                name, address = config.parse_username(names[i])
1452
 
                if name:
1453
 
                    names[i] = name
1454
 
                else:
1455
 
                    names[i] = address
1456
 
        if sep is not None:
1457
 
            names = sep.join(names)
1458
 
        return names
 
1415
        name, address = config.parse_username(rev.get_apparent_authors()[0])
 
1416
        if name:
 
1417
            return name
 
1418
        return address
1459
1419
 
1460
1420
    def merge_marker(self, revision):
1461
1421
        """Get the merge marker to include in the output or '' if none."""
1563
1523
        lines.extend(self.custom_properties(revision.rev))
1564
1524
 
1565
1525
        committer = revision.rev.committer
1566
 
        authors = self.authors(revision.rev, 'all')
 
1526
        authors = revision.rev.get_apparent_authors()
1567
1527
        if authors != [committer]:
1568
1528
            lines.append('author: %s' % (", ".join(authors),))
1569
1529
        lines.append('committer: %s' % (committer,))
1743
1703
                               self.show_timezone,
1744
1704
                               date_fmt='%Y-%m-%d',
1745
1705
                               show_offset=False)
1746
 
        committer_str = self.authors(revision.rev, 'first', sep=', ')
1747
 
        committer_str = committer_str.replace(' <', '  <')
 
1706
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
1748
1707
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1749
1708
 
1750
1709
        if revision.delta is not None and revision.delta.has_changed():
1815
1774
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1816
1775
 
1817
1776
 
1818
 
def author_list_all(rev):
1819
 
    return rev.get_apparent_authors()[:]
1820
 
 
1821
 
 
1822
 
def author_list_first(rev):
1823
 
    lst = rev.get_apparent_authors()
1824
 
    try:
1825
 
        return [lst[0]]
1826
 
    except IndexError:
1827
 
        return []
1828
 
 
1829
 
 
1830
 
def author_list_committer(rev):
1831
 
    return [rev.committer]
1832
 
 
1833
 
 
1834
 
author_list_registry = registry.Registry()
1835
 
 
1836
 
author_list_registry.register('all', author_list_all,
1837
 
                              'All authors')
1838
 
 
1839
 
author_list_registry.register('first', author_list_first,
1840
 
                              'The first author')
1841
 
 
1842
 
author_list_registry.register('committer', author_list_committer,
1843
 
                              'The committer')
1844
 
 
1845
 
 
1846
1777
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1847
1778
    # deprecated; for compatibility
1848
1779
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1999
1930
        lf.log_revision(lr)
2000
1931
 
2001
1932
 
2002
 
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
 
1933
def _get_info_for_log_files(revisionspec_list, file_list):
2003
1934
    """Find file-ids and kinds given a list of files and a revision range.
2004
1935
 
2005
1936
    We search for files at the end of the range. If not found there,
2009
1940
    :param file_list: the list of paths given on the command line;
2010
1941
      the first of these can be a branch location or a file path,
2011
1942
      the remainder must be file paths
2012
 
    :param add_cleanup: When the branch returned is read locked,
2013
 
      an unlock call will be queued to the cleanup.
2014
1943
    :return: (branch, info_list, start_rev_info, end_rev_info) where
2015
1944
      info_list is a list of (relative_path, file_id, kind) tuples where
2016
1945
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2017
1946
      branch will be read-locked.
2018
1947
    """
2019
 
    from builtins import _get_revision_range
 
1948
    from builtins import _get_revision_range, safe_relpath_files
2020
1949
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2021
 
    add_cleanup(b.lock_read().unlock)
 
1950
    b.lock_read()
2022
1951
    # XXX: It's damn messy converting a list of paths to relative paths when
2023
1952
    # those paths might be deleted ones, they might be on a case-insensitive
2024
1953
    # filesystem and/or they might be in silly locations (like another branch).
2028
1957
    # case of running log in a nested directory, assuming paths beyond the
2029
1958
    # first one haven't been deleted ...
2030
1959
    if tree:
2031
 
        relpaths = [path] + tree.safe_relpath_files(file_list[1:])
 
1960
        relpaths = [path] + safe_relpath_files(tree, file_list[1:])
2032
1961
    else:
2033
1962
        relpaths = [path] + file_list[1:]
2034
1963
    info_list = []