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, exclude_common_ancestry)
526
526
if direction == 'forward':
527
527
iter_revs = reversed(iter_revs)
544
544
return [(rev_id, revno_str, 0)]
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:
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
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.
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
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
1342
1349
def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
1350
delta_format=None, levels=None, show_advice=False,
1344
to_exact_file=None):
1351
to_exact_file=None, author_list_handler=None):
1345
1352
"""Create a LogFormatter.
1347
1354
:param to_file: the file to output to
1355
1362
let the log formatter decide.
1356
1363
:param show_advice: whether to show advice at the end of the
1365
:param author_list_handler: callable generating a list of
1366
authors to display for a given revision
1359
1368
self.to_file = to_file
1360
1369
# 'exact' stream used to show diff, it should print content 'as is'
1414
1424
def short_author(self, rev):
1415
name, address = config.parse_username(rev.get_apparent_authors()[0])
1425
return self.authors(rev, 'first', short=True, sep=', ')
1427
def authors(self, rev, who, short=False, sep=None):
1428
"""Generate list of authors, taking --authors option into account.
1430
The caller has to specify the name of a author list handler,
1431
as provided by the author list registry, using the ``who``
1432
argument. That name only sets a default, though: when the
1433
user selected a different author list generation using the
1434
``--authors`` command line switch, as represented by the
1435
``author_list_handler`` constructor argument, that value takes
1438
:param rev: The revision for which to generate the list of authors.
1439
:param who: Name of the default handler.
1440
:param short: Whether to shorten names to either name or address.
1441
:param sep: What separator to use for automatic concatenation.
1443
if self._author_list_handler is not None:
1444
# The user did specify --authors, which overrides the default
1445
author_list_handler = self._author_list_handler
1447
# The user didn't specify --authors, so we use the caller's default
1448
author_list_handler = author_list_registry.get(who)
1449
names = author_list_handler(rev)
1451
for i in range(len(names)):
1452
name, address = config.parse_username(names[i])
1458
names = sep.join(names)
1420
1461
def merge_marker(self, revision):
1421
1462
"""Get the merge marker to include in the output or '' if none."""
1523
1564
lines.extend(self.custom_properties(revision.rev))
1525
1566
committer = revision.rev.committer
1526
authors = revision.rev.get_apparent_authors()
1567
authors = self.authors(revision.rev, 'all')
1527
1568
if authors != [committer]:
1528
1569
lines.append('author: %s' % (", ".join(authors),))
1529
1570
lines.append('committer: %s' % (committer,))
1703
1744
self.show_timezone,
1704
1745
date_fmt='%Y-%m-%d',
1705
1746
show_offset=False)
1706
committer_str = revision.rev.get_apparent_authors()[0].replace (' <', ' <')
1747
committer_str = self.authors(revision.rev, 'first', sep=', ')
1748
committer_str = committer_str.replace(' <', ' <')
1707
1749
to_file.write('%s %s\n\n' % (date_str,committer_str))
1709
1751
if revision.delta is not None and revision.delta.has_changed():
1774
1816
raise errors.BzrCommandError("unknown log formatter: %r" % name)
1819
def author_list_all(rev):
1820
return rev.get_apparent_authors()[:]
1823
def author_list_first(rev):
1824
lst = rev.get_apparent_authors()
1831
def author_list_committer(rev):
1832
return [rev.committer]
1835
author_list_registry = registry.Registry()
1837
author_list_registry.register('all', author_list_all,
1840
author_list_registry.register('first', author_list_first,
1843
author_list_registry.register('committer', author_list_committer,
1777
1847
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1778
1848
# deprecated; for compatibility
1779
1849
lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1930
2000
lf.log_revision(lr)
1933
def _get_info_for_log_files(revisionspec_list, file_list):
2003
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
1934
2004
"""Find file-ids and kinds given a list of files and a revision range.
1936
2006
We search for files at the end of the range. If not found there,
1940
2010
:param file_list: the list of paths given on the command line;
1941
2011
the first of these can be a branch location or a file path,
1942
2012
the remainder must be file paths
2013
:param add_cleanup: When the branch returned is read locked,
2014
an unlock call will be queued to the cleanup.
1943
2015
:return: (branch, info_list, start_rev_info, end_rev_info) where
1944
2016
info_list is a list of (relative_path, file_id, kind) tuples where
1945
2017
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1948
2020
from builtins import _get_revision_range, safe_relpath_files
1949
2021
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2022
add_cleanup(b.lock_read().unlock)
1951
2023
# XXX: It's damn messy converting a list of paths to relative paths when
1952
2024
# those paths might be deleted ones, they might be on a case-insensitive
1953
2025
# filesystem and/or they might be in silly locations (like another branch).