~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Robert Collins
  • Date: 2010-05-11 08:44:59 UTC
  • mfrom: (5221 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100511084459-pb0uinna9zs3wu59
Merge trunk - resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1341
1341
 
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.
1346
1346
 
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
1357
1357
          log or not
 
1358
        :param author_list_handler: callable generating a list of
 
1359
          authors to display for a given revision
1358
1360
        """
1359
1361
        self.to_file = to_file
1360
1362
        # 'exact' stream used to show diff, it should print content 'as is'
1375
1377
        self.levels = levels
1376
1378
        self._show_advice = show_advice
1377
1379
        self._merge_count = 0
 
1380
        self._author_list_handler = author_list_handler
1378
1381
 
1379
1382
    def get_levels(self):
1380
1383
        """Get the number of levels to display or 0 for all."""
1412
1415
        return address
1413
1416
 
1414
1417
    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
 
1418
        return self.authors(rev, 'first', short=True, sep=', ')
 
1419
 
 
1420
    def authors(self, rev, who, short=False, sep=None):
 
1421
        """Generate list of authors, taking --authors option into account.
 
1422
 
 
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
 
1429
        precedence.
 
1430
 
 
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.
 
1435
        """
 
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
 
1439
        else:
 
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)
 
1443
        if short:
 
1444
            for i in range(len(names)):
 
1445
                name, address = config.parse_username(names[i])
 
1446
                if name:
 
1447
                    names[i] = name
 
1448
                else:
 
1449
                    names[i] = address
 
1450
        if sep is not None:
 
1451
            names = sep.join(names)
 
1452
        return names
1419
1453
 
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))
1524
1558
 
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))
1708
1743
 
1709
1744
        if revision.delta is not None and revision.delta.has_changed():
1774
1809
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1775
1810
 
1776
1811
 
 
1812
def author_list_all(rev):
 
1813
    return rev.get_apparent_authors()[:]
 
1814
 
 
1815
 
 
1816
def author_list_first(rev):
 
1817
    lst = rev.get_apparent_authors()
 
1818
    try:
 
1819
        return [lst[0]]
 
1820
    except IndexError:
 
1821
        return []
 
1822
 
 
1823
 
 
1824
def author_list_committer(rev):
 
1825
    return [rev.committer]
 
1826
 
 
1827
 
 
1828
author_list_registry = registry.Registry()
 
1829
 
 
1830
author_list_registry.register('all', author_list_all,
 
1831
                              'All authors')
 
1832
 
 
1833
author_list_registry.register('first', author_list_first,
 
1834
                              'The first author')
 
1835
 
 
1836
author_list_registry.register('committer', author_list_committer,
 
1837
                              'The committer')
 
1838
 
 
1839
 
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)