1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
84
83
from bzrlib.osutils import (
86
85
format_date_with_offset_in_original_timezone,
86
get_diff_header_encoding,
87
87
get_terminal_encoding,
91
90
from bzrlib.symbol_versioning import (
433
432
specific_files = None
434
path_encoding = get_diff_header_encoding()
435
435
diff.show_diff_trees(tree_1, tree_2, s, specific_files, old_label='',
436
new_label='', path_encoding=path_encoding)
437
437
return s.getvalue()
439
439
def _create_log_revision_iterator(self):
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
803
810
if search is None:
804
811
return log_rev_iterator
805
searchRE = re_compile_checked(search, re.IGNORECASE,
806
'log message filter')
812
searchRE = re.compile(search, re.IGNORECASE)
807
813
return _filter_message_re(searchRE, log_rev_iterator)
1342
1348
def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
1349
delta_format=None, levels=None, show_advice=False,
1344
to_exact_file=None):
1350
to_exact_file=None, author_list_handler=None):
1345
1351
"""Create a LogFormatter.
1347
1353
:param to_file: the file to output to
1355
1361
let the log formatter decide.
1356
1362
:param show_advice: whether to show advice at the end of the
1364
:param author_list_handler: callable generating a list of
1365
authors to display for a given revision
1359
1367
self.to_file = to_file
1360
1368
# 'exact' stream used to show diff, it should print content 'as is'
1414
1423
def short_author(self, rev):
1415
name, address = config.parse_username(rev.get_apparent_authors()[0])
1424
return self.authors(rev, 'first', short=True, sep=', ')
1426
def authors(self, rev, who, short=False, sep=None):
1427
"""Generate list of authors, taking --authors option into account.
1429
The caller has to specify the name of a author list handler,
1430
as provided by the author list registry, using the ``who``
1431
argument. That name only sets a default, though: when the
1432
user selected a different author list generation using the
1433
``--authors`` command line switch, as represented by the
1434
``author_list_handler`` constructor argument, that value takes
1437
:param rev: The revision for which to generate the list of authors.
1438
:param who: Name of the default handler.
1439
:param short: Whether to shorten names to either name or address.
1440
:param sep: What separator to use for automatic concatenation.
1442
if self._author_list_handler is not None:
1443
# The user did specify --authors, which overrides the default
1444
author_list_handler = self._author_list_handler
1446
# The user didn't specify --authors, so we use the caller's default
1447
author_list_handler = author_list_registry.get(who)
1448
names = author_list_handler(rev)
1450
for i in range(len(names)):
1451
name, address = config.parse_username(names[i])
1457
names = sep.join(names)
1420
1460
def merge_marker(self, revision):
1421
1461
"""Get the merge marker to include in the output or '' if none."""
1523
1563
lines.extend(self.custom_properties(revision.rev))
1525
1565
committer = revision.rev.committer
1526
authors = revision.rev.get_apparent_authors()
1566
authors = self.authors(revision.rev, 'all')
1527
1567
if authors != [committer]:
1528
1568
lines.append('author: %s' % (", ".join(authors),))
1529
1569
lines.append('committer: %s' % (committer,))
1703
1743
self.show_timezone,
1704
1744
date_fmt='%Y-%m-%d',
1705
1745
show_offset=False)
1706
committer_str = revision.rev.get_apparent_authors()[0].replace (' <', ' <')
1746
committer_str = self.authors(revision.rev, 'first', sep=', ')
1747
committer_str = committer_str.replace(' <', ' <')
1707
1748
to_file.write('%s %s\n\n' % (date_str,committer_str))
1709
1750
if revision.delta is not None and revision.delta.has_changed():
1774
1815
raise errors.BzrCommandError("unknown log formatter: %r" % name)
1818
def author_list_all(rev):
1819
return rev.get_apparent_authors()[:]
1822
def author_list_first(rev):
1823
lst = rev.get_apparent_authors()
1830
def author_list_committer(rev):
1831
return [rev.committer]
1834
author_list_registry = registry.Registry()
1836
author_list_registry.register('all', author_list_all,
1839
author_list_registry.register('first', author_list_first,
1842
author_list_registry.register('committer', author_list_committer,
1777
1846
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1778
1847
# deprecated; for compatibility
1779
1848
lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1930
1999
lf.log_revision(lr)
1933
def _get_info_for_log_files(revisionspec_list, file_list):
2002
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
1934
2003
"""Find file-ids and kinds given a list of files and a revision range.
1936
2005
We search for files at the end of the range. If not found there,
1940
2009
:param file_list: the list of paths given on the command line;
1941
2010
the first of these can be a branch location or a file path,
1942
2011
the remainder must be file paths
2012
:param add_cleanup: When the branch returned is read locked,
2013
an unlock call will be queued to the cleanup.
1943
2014
:return: (branch, info_list, start_rev_info, end_rev_info) where
1944
2015
info_list is a list of (relative_path, file_id, kind) tuples where
1945
2016
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1946
2017
branch will be read-locked.
1948
from builtins import _get_revision_range, safe_relpath_files
2019
from builtins import _get_revision_range
1949
2020
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2021
add_cleanup(b.lock_read().unlock)
1951
2022
# XXX: It's damn messy converting a list of paths to relative paths when
1952
2023
# those paths might be deleted ones, they might be on a case-insensitive
1953
2024
# filesystem and/or they might be in silly locations (like another branch).
1957
2028
# case of running log in a nested directory, assuming paths beyond the
1958
2029
# first one haven't been deleted ...
1960
relpaths = [path] + safe_relpath_files(tree, file_list[1:])
2031
relpaths = [path] + tree.safe_relpath_files(file_list[1:])
1962
2033
relpaths = [path] + file_list[1:]