/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

merge diff header work from my 2.1 branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
    diff,
71
71
    errors,
72
72
    foreign,
 
73
    osutils,
73
74
    repository as _mod_repository,
74
75
    revision as _mod_revision,
75
76
    revisionspec,
432
433
        else:
433
434
            specific_files = None
434
435
        s = StringIO()
 
436
        path_encoding = osutils.get_diff_header_encoding()
435
437
        diff.show_diff_trees(tree_1, tree_2, s, specific_files, old_label='',
436
 
            new_label='')
 
438
            new_label='', path_encoding=path_encoding)
437
439
        return s.getvalue()
438
440
 
439
441
    def _create_log_revision_iterator(self):
1341
1343
 
1342
1344
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
1345
                 delta_format=None, levels=None, show_advice=False,
1344
 
                 to_exact_file=None):
 
1346
                 to_exact_file=None, author_list_handler=None):
1345
1347
        """Create a LogFormatter.
1346
1348
 
1347
1349
        :param to_file: the file to output to
1355
1357
          let the log formatter decide.
1356
1358
        :param show_advice: whether to show advice at the end of the
1357
1359
          log or not
 
1360
        :param author_list_handler: callable generating a list of
 
1361
          authors to display for a given revision
1358
1362
        """
1359
1363
        self.to_file = to_file
1360
1364
        # 'exact' stream used to show diff, it should print content 'as is'
1375
1379
        self.levels = levels
1376
1380
        self._show_advice = show_advice
1377
1381
        self._merge_count = 0
 
1382
        self._author_list_handler = author_list_handler
1378
1383
 
1379
1384
    def get_levels(self):
1380
1385
        """Get the number of levels to display or 0 for all."""
1412
1417
        return address
1413
1418
 
1414
1419
    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
 
1420
        return self.authors(rev, 'first', short=True, sep=', ')
 
1421
 
 
1422
    def authors(self, rev, who, short=False, sep=None):
 
1423
        """Generate list of authors, taking --authors option into account.
 
1424
 
 
1425
        The caller has to specify the name of a author list handler,
 
1426
        as provided by the author list registry, using the ``who``
 
1427
        argument.  That name only sets a default, though: when the
 
1428
        user selected a different author list generation using the
 
1429
        ``--authors`` command line switch, as represented by the
 
1430
        ``author_list_handler`` constructor argument, that value takes
 
1431
        precedence.
 
1432
 
 
1433
        :param rev: The revision for which to generate the list of authors.
 
1434
        :param who: Name of the default handler.
 
1435
        :param short: Whether to shorten names to either name or address.
 
1436
        :param sep: What separator to use for automatic concatenation.
 
1437
        """
 
1438
        if self._author_list_handler is not None:
 
1439
            # The user did specify --authors, which overrides the default
 
1440
            author_list_handler = self._author_list_handler
 
1441
        else:
 
1442
            # The user didn't specify --authors, so we use the caller's default
 
1443
            author_list_handler = author_list_registry.get(who)
 
1444
        names = author_list_handler(rev)
 
1445
        if short:
 
1446
            for i in range(len(names)):
 
1447
                name, address = config.parse_username(names[i])
 
1448
                if name:
 
1449
                    names[i] = name
 
1450
                else:
 
1451
                    names[i] = address
 
1452
        if sep is not None:
 
1453
            names = sep.join(names)
 
1454
        return names
1419
1455
 
1420
1456
    def merge_marker(self, revision):
1421
1457
        """Get the merge marker to include in the output or '' if none."""
1523
1559
        lines.extend(self.custom_properties(revision.rev))
1524
1560
 
1525
1561
        committer = revision.rev.committer
1526
 
        authors = revision.rev.get_apparent_authors()
 
1562
        authors = self.authors(revision.rev, 'all')
1527
1563
        if authors != [committer]:
1528
1564
            lines.append('author: %s' % (", ".join(authors),))
1529
1565
        lines.append('committer: %s' % (committer,))
1703
1739
                               self.show_timezone,
1704
1740
                               date_fmt='%Y-%m-%d',
1705
1741
                               show_offset=False)
1706
 
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
 
1742
        committer_str = self.authors(revision.rev, 'first', sep=', ')
 
1743
        committer_str = committer_str.replace(' <', '  <')
1707
1744
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1708
1745
 
1709
1746
        if revision.delta is not None and revision.delta.has_changed():
1774
1811
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1775
1812
 
1776
1813
 
 
1814
def author_list_all(rev):
 
1815
    return rev.get_apparent_authors()[:]
 
1816
 
 
1817
 
 
1818
def author_list_first(rev):
 
1819
    lst = rev.get_apparent_authors()
 
1820
    try:
 
1821
        return [lst[0]]
 
1822
    except IndexError:
 
1823
        return []
 
1824
 
 
1825
 
 
1826
def author_list_committer(rev):
 
1827
    return [rev.committer]
 
1828
 
 
1829
 
 
1830
author_list_registry = registry.Registry()
 
1831
 
 
1832
author_list_registry.register('all', author_list_all,
 
1833
                              'All authors')
 
1834
 
 
1835
author_list_registry.register('first', author_list_first,
 
1836
                              'The first author')
 
1837
 
 
1838
author_list_registry.register('committer', author_list_committer,
 
1839
                              'The committer')
 
1840
 
 
1841
 
1777
1842
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1778
1843
    # deprecated; for compatibility
1779
1844
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1930
1995
        lf.log_revision(lr)
1931
1996
 
1932
1997
 
1933
 
def _get_info_for_log_files(revisionspec_list, file_list):
 
1998
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
1934
1999
    """Find file-ids and kinds given a list of files and a revision range.
1935
2000
 
1936
2001
    We search for files at the end of the range. If not found there,
1940
2005
    :param file_list: the list of paths given on the command line;
1941
2006
      the first of these can be a branch location or a file path,
1942
2007
      the remainder must be file paths
 
2008
    :param add_cleanup: When the branch returned is read locked,
 
2009
      an unlock call will be queued to the cleanup.
1943
2010
    :return: (branch, info_list, start_rev_info, end_rev_info) where
1944
2011
      info_list is a list of (relative_path, file_id, kind) tuples where
1945
2012
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1947
2014
    """
1948
2015
    from builtins import _get_revision_range, safe_relpath_files
1949
2016
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
1950
 
    b.lock_read()
 
2017
    add_cleanup(b.lock_read().unlock)
1951
2018
    # XXX: It's damn messy converting a list of paths to relative paths when
1952
2019
    # those paths might be deleted ones, they might be on a case-insensitive
1953
2020
    # filesystem and/or they might be in silly locations (like another branch).