~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:54:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506235405-wii4elupfhzl3jvy
Add __str__ to the new helper classes.

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, author_list_handler=None):
 
1344
                 to_exact_file=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
1360
1358
        """
1361
1359
        self.to_file = to_file
1362
1360
        # 'exact' stream used to show diff, it should print content 'as is'
1377
1375
        self.levels = levels
1378
1376
        self._show_advice = show_advice
1379
1377
        self._merge_count = 0
1380
 
        self._author_list_handler = author_list_handler
1381
1378
 
1382
1379
    def get_levels(self):
1383
1380
        """Get the number of levels to display or 0 for all."""
1415
1412
        return address
1416
1413
 
1417
1414
    def short_author(self, rev):
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
 
1415
        name, address = config.parse_username(rev.get_apparent_authors()[0])
 
1416
        if name:
 
1417
            return name
 
1418
        return address
1453
1419
 
1454
1420
    def merge_marker(self, revision):
1455
1421
        """Get the merge marker to include in the output or '' if none."""
1557
1523
        lines.extend(self.custom_properties(revision.rev))
1558
1524
 
1559
1525
        committer = revision.rev.committer
1560
 
        authors = self.authors(revision.rev, 'all')
 
1526
        authors = revision.rev.get_apparent_authors()
1561
1527
        if authors != [committer]:
1562
1528
            lines.append('author: %s' % (", ".join(authors),))
1563
1529
        lines.append('committer: %s' % (committer,))
1737
1703
                               self.show_timezone,
1738
1704
                               date_fmt='%Y-%m-%d',
1739
1705
                               show_offset=False)
1740
 
        committer_str = self.authors(revision.rev, 'first', sep=', ')
1741
 
        committer_str = committer_str.replace(' <', '  <')
 
1706
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
1742
1707
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1743
1708
 
1744
1709
        if revision.delta is not None and revision.delta.has_changed():
1809
1774
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1810
1775
 
1811
1776
 
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
 
 
1840
1777
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1841
1778
    # deprecated; for compatibility
1842
1779
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)