/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: John Arbash Meinel
  • Date: 2011-04-07 10:36:24 UTC
  • mfrom: (5764 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5766.
  • Revision ID: john@arbash-meinel.com-20110407103624-n76g6tjeqmznwdcd
Merge bzr.dev 5764 to resolve release-notes (aka NEWS) conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
73
73
    repository as _mod_repository,
74
74
    revision as _mod_revision,
75
75
    revisionspec,
76
 
    trace,
77
76
    tsort,
78
77
    )
79
78
""")
84
83
from bzrlib.osutils import (
85
84
    format_date,
86
85
    format_date_with_offset_in_original_timezone,
 
86
    get_diff_header_encoding,
87
87
    get_terminal_encoding,
88
 
    re_compile_checked,
89
88
    terminal_width,
90
89
    )
91
90
from bzrlib.symbol_versioning import (
298
297
 
299
298
def _apply_log_request_defaults(rqst):
300
299
    """Apply default values to a request dictionary."""
301
 
    result = _DEFAULT_REQUEST_PARAMS
 
300
    result = _DEFAULT_REQUEST_PARAMS.copy()
302
301
    if rqst:
303
302
        result.update(rqst)
304
303
    return result
432
431
        else:
433
432
            specific_files = None
434
433
        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='')
 
436
            new_label='', path_encoding=path_encoding)
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)
 
525
                                             direction, exclude_common_ancestry)
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
 
    result = _linear_view_revisions(branch, start_rev_id, end_rev_id)
 
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)
549
552
    # If a start limit was given and it's not obviously an
550
553
    # ancestor of the end limit, check it before outputting anything
551
554
    if direction == 'forward' or (start_rev_id
572
575
    if delayed_graph_generation:
573
576
        try:
574
577
            for rev_id, revno, depth in  _linear_view_revisions(
575
 
                branch, start_rev_id, end_rev_id):
 
578
                branch, start_rev_id, end_rev_id, exclude_common_ancestry):
576
579
                if _has_merges(branch, rev_id):
577
580
                    # The end_rev_id can be nested down somewhere. We need an
578
581
                    # explicit ancestry check. There is an ambiguity here as we
643
646
    return True
644
647
 
645
648
 
646
 
def _linear_view_revisions(branch, start_rev_id, end_rev_id):
 
649
def _linear_view_revisions(branch, start_rev_id, end_rev_id,
 
650
                           exclude_common_ancestry=False):
647
651
    """Calculate a sequence of revisions to view, newest to oldest.
648
652
 
649
653
    :param start_rev_id: the lower revision-id
650
654
    :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.
651
657
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
652
658
    :raises _StartNotLinearAncestor: if a start_rev_id is specified but
653
 
      is not found walking the left-hand history
 
659
        is not found walking the left-hand history
654
660
    """
655
661
    br_revno, br_rev_id = branch.last_revision_info()
656
662
    repo = branch.repository
667
673
            revno = branch.revision_id_to_dotted_revno(revision_id)
668
674
            revno_str = '.'.join(str(n) for n in revno)
669
675
            if not found_start and revision_id == start_rev_id:
670
 
                yield revision_id, revno_str, 0
 
676
                if not exclude_common_ancestry:
 
677
                    yield revision_id, revno_str, 0
671
678
                found_start = True
672
679
                break
673
680
            else:
802
809
    """
803
810
    if search is None:
804
811
        return log_rev_iterator
805
 
    searchRE = re_compile_checked(search, re.IGNORECASE,
806
 
            'log message filter')
 
812
    searchRE = re.compile(search, re.IGNORECASE)
807
813
    return _filter_message_re(searchRE, log_rev_iterator)
808
814
 
809
815
 
1341
1347
 
1342
1348
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
1349
                 delta_format=None, levels=None, show_advice=False,
1344
 
                 to_exact_file=None):
 
1350
                 to_exact_file=None, author_list_handler=None):
1345
1351
        """Create a LogFormatter.
1346
1352
 
1347
1353
        :param to_file: the file to output to
1355
1361
          let the log formatter decide.
1356
1362
        :param show_advice: whether to show advice at the end of the
1357
1363
          log or not
 
1364
        :param author_list_handler: callable generating a list of
 
1365
          authors to display for a given revision
1358
1366
        """
1359
1367
        self.to_file = to_file
1360
1368
        # 'exact' stream used to show diff, it should print content 'as is'
1375
1383
        self.levels = levels
1376
1384
        self._show_advice = show_advice
1377
1385
        self._merge_count = 0
 
1386
        self._author_list_handler = author_list_handler
1378
1387
 
1379
1388
    def get_levels(self):
1380
1389
        """Get the number of levels to display or 0 for all."""
1412
1421
        return address
1413
1422
 
1414
1423
    def short_author(self, rev):
1415
 
        name, address = config.parse_username(rev.get_apparent_authors()[0])
1416
 
        if name:
1417
 
            return name
1418
 
        return address
 
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
1419
1459
 
1420
1460
    def merge_marker(self, revision):
1421
1461
        """Get the merge marker to include in the output or '' if none."""
1523
1563
        lines.extend(self.custom_properties(revision.rev))
1524
1564
 
1525
1565
        committer = revision.rev.committer
1526
 
        authors = revision.rev.get_apparent_authors()
 
1566
        authors = self.authors(revision.rev, 'all')
1527
1567
        if authors != [committer]:
1528
1568
            lines.append('author: %s' % (", ".join(authors),))
1529
1569
        lines.append('committer: %s' % (committer,))
1703
1743
                               self.show_timezone,
1704
1744
                               date_fmt='%Y-%m-%d',
1705
1745
                               show_offset=False)
1706
 
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
 
1746
        committer_str = self.authors(revision.rev, 'first', sep=', ')
 
1747
        committer_str = committer_str.replace(' <', '  <')
1707
1748
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1708
1749
 
1709
1750
        if revision.delta is not None and revision.delta.has_changed():
1774
1815
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1775
1816
 
1776
1817
 
 
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
 
1777
1846
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1778
1847
    # deprecated; for compatibility
1779
1848
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1930
1999
        lf.log_revision(lr)
1931
2000
 
1932
2001
 
1933
 
def _get_info_for_log_files(revisionspec_list, file_list):
 
2002
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
1934
2003
    """Find file-ids and kinds given a list of files and a revision range.
1935
2004
 
1936
2005
    We search for files at the end of the range. If not found there,
1940
2009
    :param file_list: the list of paths given on the command line;
1941
2010
      the first of these can be a branch location or a file path,
1942
2011
      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.
1943
2014
    :return: (branch, info_list, start_rev_info, end_rev_info) where
1944
2015
      info_list is a list of (relative_path, file_id, kind) tuples where
1945
2016
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1946
2017
      branch will be read-locked.
1947
2018
    """
1948
 
    from builtins import _get_revision_range, safe_relpath_files
 
2019
    from builtins import _get_revision_range
1949
2020
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
1950
 
    b.lock_read()
 
2021
    add_cleanup(b.lock_read().unlock)
1951
2022
    # XXX: It's damn messy converting a list of paths to relative paths when
1952
2023
    # those paths might be deleted ones, they might be on a case-insensitive
1953
2024
    # filesystem and/or they might be in silly locations (like another branch).
1957
2028
    # case of running log in a nested directory, assuming paths beyond the
1958
2029
    # first one haven't been deleted ...
1959
2030
    if tree:
1960
 
        relpaths = [path] + safe_relpath_files(tree, file_list[1:])
 
2031
        relpaths = [path] + tree.safe_relpath_files(file_list[1:])
1961
2032
    else:
1962
2033
        relpaths = [path] + file_list[1:]
1963
2034
    info_list = []