1342
1342
def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
1343
delta_format=None, levels=None, show_advice=False,
1344
to_exact_file=None):
1344
to_exact_file=None, author_list_handler=None):
1345
1345
"""Create a LogFormatter.
1347
1347
:param to_file: the file to output to
1355
1355
let the log formatter decide.
1356
1356
:param show_advice: whether to show advice at the end of the
1358
:param author_list_handler: callable generating a list of
1359
authors to display for a given revision
1359
1361
self.to_file = to_file
1360
1362
# 'exact' stream used to show diff, it should print content 'as is'
1414
1417
def short_author(self, rev):
1415
name, address = config.parse_username(rev.get_apparent_authors()[0])
1418
return self.authors(rev, 'first', short=True, sep=', ')
1420
def authors(self, rev, who, short=False, sep=None):
1421
"""Generate list of authors, taking --authors option into account.
1423
The caller has to specify the name of a author list handler,
1424
as provided by the author list registry, using the ``who``
1425
argument. That name only sets a default, though: when the
1426
user selected a different author list generation using the
1427
``--authors`` command line switch, as represented by the
1428
``author_list_handler`` constructor argument, that value takes
1431
:param rev: The revision for which to generate the list of authors.
1432
:param who: Name of the default handler.
1433
:param short: Whether to shorten names to either name or address.
1434
:param sep: What separator to use for automatic concatenation.
1436
if self._author_list_handler is not None:
1437
# The user did specify --authors, which overrides the default
1438
author_list_handler = self._author_list_handler
1440
# The user didn't specify --authors, so we use the caller's default
1441
author_list_handler = author_list_registry.get(who)
1442
names = author_list_handler(rev)
1444
for i in range(len(names)):
1445
name, address = config.parse_username(names[i])
1451
names = sep.join(names)
1420
1454
def merge_marker(self, revision):
1421
1455
"""Get the merge marker to include in the output or '' if none."""
1523
1557
lines.extend(self.custom_properties(revision.rev))
1525
1559
committer = revision.rev.committer
1526
authors = revision.rev.get_apparent_authors()
1560
authors = self.authors(revision.rev, 'all')
1527
1561
if authors != [committer]:
1528
1562
lines.append('author: %s' % (", ".join(authors),))
1529
1563
lines.append('committer: %s' % (committer,))
1703
1737
self.show_timezone,
1704
1738
date_fmt='%Y-%m-%d',
1705
1739
show_offset=False)
1706
committer_str = revision.rev.get_apparent_authors()[0].replace (' <', ' <')
1740
committer_str = self.authors(revision.rev, 'first', sep=', ')
1741
committer_str = committer_str.replace(' <', ' <')
1707
1742
to_file.write('%s %s\n\n' % (date_str,committer_str))
1709
1744
if revision.delta is not None and revision.delta.has_changed():
1774
1809
raise errors.BzrCommandError("unknown log formatter: %r" % name)
1812
def author_list_all(rev):
1813
return rev.get_apparent_authors()[:]
1816
def author_list_first(rev):
1817
lst = rev.get_apparent_authors()
1824
def author_list_committer(rev):
1825
return [rev.committer]
1828
author_list_registry = registry.Registry()
1830
author_list_registry.register('all', author_list_all,
1833
author_list_registry.register('first', author_list_first,
1836
author_list_registry.register('committer', author_list_committer,
1777
1840
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1778
1841
# deprecated; for compatibility
1779
1842
lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)