434
433
specific_files = None
436
path_encoding = osutils.get_diff_header_encoding()
437
435
diff.show_diff_trees(tree_1, tree_2, s, specific_files, old_label='',
438
new_label='', path_encoding=path_encoding)
439
437
return s.getvalue()
441
439
def _create_log_revision_iterator(self):
524
522
elif not generate_merge_revisions:
525
523
# If we only want to see linear revisions, we can iterate ...
526
524
iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
527
direction, exclude_common_ancestry)
528
526
if direction == 'forward':
529
527
iter_revs = reversed(iter_revs)
546
544
return [(rev_id, revno_str, 0)]
549
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction,
550
exclude_common_ancestry=False):
551
result = _linear_view_revisions(
552
branch, start_rev_id, end_rev_id,
553
exclude_common_ancestry=exclude_common_ancestry)
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)
554
549
# If a start limit was given and it's not obviously an
555
550
# ancestor of the end limit, check it before outputting anything
556
551
if direction == 'forward' or (start_rev_id
577
572
if delayed_graph_generation:
579
574
for rev_id, revno, depth in _linear_view_revisions(
580
branch, start_rev_id, end_rev_id, exclude_common_ancestry):
575
branch, start_rev_id, end_rev_id):
581
576
if _has_merges(branch, rev_id):
582
577
# The end_rev_id can be nested down somewhere. We need an
583
578
# explicit ancestry check. There is an ambiguity here as we
651
def _linear_view_revisions(branch, start_rev_id, end_rev_id,
652
exclude_common_ancestry=False):
646
def _linear_view_revisions(branch, start_rev_id, end_rev_id):
653
647
"""Calculate a sequence of revisions to view, newest to oldest.
655
649
:param start_rev_id: the lower revision-id
656
650
:param end_rev_id: the upper revision-id
657
:param exclude_common_ancestry: Whether the start_rev_id should be part of
658
the iterated revisions.
659
651
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
660
652
:raises _StartNotLinearAncestor: if a start_rev_id is specified but
661
is not found walking the left-hand history
653
is not found walking the left-hand history
663
655
br_revno, br_rev_id = branch.last_revision_info()
664
656
repo = branch.repository
675
667
revno = branch.revision_id_to_dotted_revno(revision_id)
676
668
revno_str = '.'.join(str(n) for n in revno)
677
669
if not found_start and revision_id == start_rev_id:
678
if not exclude_common_ancestry:
679
yield revision_id, revno_str, 0
670
yield revision_id, revno_str, 0
680
671
found_start = True
1351
1342
def __init__(self, to_file, show_ids=False, show_timezone='original',
1352
1343
delta_format=None, levels=None, show_advice=False,
1353
to_exact_file=None, author_list_handler=None):
1344
to_exact_file=None):
1354
1345
"""Create a LogFormatter.
1356
1347
:param to_file: the file to output to
1364
1355
let the log formatter decide.
1365
1356
:param show_advice: whether to show advice at the end of the
1367
:param author_list_handler: callable generating a list of
1368
authors to display for a given revision
1370
1359
self.to_file = to_file
1371
1360
# 'exact' stream used to show diff, it should print content 'as is'
1426
1414
def short_author(self, rev):
1427
return self.authors(rev, 'first', short=True, sep=', ')
1429
def authors(self, rev, who, short=False, sep=None):
1430
"""Generate list of authors, taking --authors option into account.
1432
The caller has to specify the name of a author list handler,
1433
as provided by the author list registry, using the ``who``
1434
argument. That name only sets a default, though: when the
1435
user selected a different author list generation using the
1436
``--authors`` command line switch, as represented by the
1437
``author_list_handler`` constructor argument, that value takes
1440
:param rev: The revision for which to generate the list of authors.
1441
:param who: Name of the default handler.
1442
:param short: Whether to shorten names to either name or address.
1443
:param sep: What separator to use for automatic concatenation.
1445
if self._author_list_handler is not None:
1446
# The user did specify --authors, which overrides the default
1447
author_list_handler = self._author_list_handler
1449
# The user didn't specify --authors, so we use the caller's default
1450
author_list_handler = author_list_registry.get(who)
1451
names = author_list_handler(rev)
1453
for i in range(len(names)):
1454
name, address = config.parse_username(names[i])
1460
names = sep.join(names)
1415
name, address = config.parse_username(rev.get_apparent_authors()[0])
1463
1420
def merge_marker(self, revision):
1464
1421
"""Get the merge marker to include in the output or '' if none."""
1566
1523
lines.extend(self.custom_properties(revision.rev))
1568
1525
committer = revision.rev.committer
1569
authors = self.authors(revision.rev, 'all')
1526
authors = revision.rev.get_apparent_authors()
1570
1527
if authors != [committer]:
1571
1528
lines.append('author: %s' % (", ".join(authors),))
1572
1529
lines.append('committer: %s' % (committer,))
1746
1703
self.show_timezone,
1747
1704
date_fmt='%Y-%m-%d',
1748
1705
show_offset=False)
1749
committer_str = self.authors(revision.rev, 'first', sep=', ')
1750
committer_str = committer_str.replace(' <', ' <')
1706
committer_str = revision.rev.get_apparent_authors()[0].replace (' <', ' <')
1751
1707
to_file.write('%s %s\n\n' % (date_str,committer_str))
1753
1709
if revision.delta is not None and revision.delta.has_changed():
1818
1774
raise errors.BzrCommandError("unknown log formatter: %r" % name)
1821
def author_list_all(rev):
1822
return rev.get_apparent_authors()[:]
1825
def author_list_first(rev):
1826
lst = rev.get_apparent_authors()
1833
def author_list_committer(rev):
1834
return [rev.committer]
1837
author_list_registry = registry.Registry()
1839
author_list_registry.register('all', author_list_all,
1842
author_list_registry.register('first', author_list_first,
1845
author_list_registry.register('committer', author_list_committer,
1849
1777
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1850
1778
# deprecated; for compatibility
1851
1779
lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
2002
1930
lf.log_revision(lr)
2005
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
1933
def _get_info_for_log_files(revisionspec_list, file_list):
2006
1934
"""Find file-ids and kinds given a list of files and a revision range.
2008
1936
We search for files at the end of the range. If not found there,
2012
1940
:param file_list: the list of paths given on the command line;
2013
1941
the first of these can be a branch location or a file path,
2014
1942
the remainder must be file paths
2015
:param add_cleanup: When the branch returned is read locked,
2016
an unlock call will be queued to the cleanup.
2017
1943
:return: (branch, info_list, start_rev_info, end_rev_info) where
2018
1944
info_list is a list of (relative_path, file_id, kind) tuples where
2019
1945
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2022
1948
from builtins import _get_revision_range, safe_relpath_files
2023
1949
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2024
add_cleanup(b.lock_read().unlock)
2025
1951
# XXX: It's damn messy converting a list of paths to relative paths when
2026
1952
# those paths might be deleted ones, they might be on a case-insensitive
2027
1953
# filesystem and/or they might be in silly locations (like another branch).