220
220
'direction': 'reverse',
222
222
'generate_tags': True,
223
'exclude_common_ancestry': False,
223
224
'_match_using_deltas': True,
227
228
def make_log_request_dict(direction='reverse', specific_fileids=None,
228
start_revision=None, end_revision=None, limit=None,
229
message_search=None, levels=1, generate_tags=True, delta_type=None,
230
diff_type=None, _match_using_deltas=True):
229
start_revision=None, end_revision=None, limit=None,
230
message_search=None, levels=1, generate_tags=True,
232
diff_type=None, _match_using_deltas=True,
233
exclude_common_ancestry=False,
231
235
"""Convenience function for making a logging request dictionary.
233
237
Using this function may make code slightly safer by ensuring
271
275
algorithm used for matching specific_fileids. This parameter
272
276
may be removed in the future so bzrlib client code should NOT
279
:param exclude_common_ancestry: Whether -rX..Y should be interpreted as a
280
range operator or as a graph difference.
276
283
'direction': direction,
283
290
'generate_tags': generate_tags,
284
291
'delta_type': delta_type,
285
292
'diff_type': diff_type,
293
'exclude_common_ancestry': exclude_common_ancestry,
286
294
# Add 'private' attributes for features that may be deprecated
287
295
'_match_using_deltas': _match_using_deltas,
459
467
self.branch, self.start_rev_id, self.end_rev_id,
460
468
rqst.get('direction'),
461
469
generate_merge_revisions=generate_merge_revisions,
462
delayed_graph_generation=delayed_graph_generation)
470
delayed_graph_generation=delayed_graph_generation,
471
exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
464
473
# Apply the other filters
465
474
return make_log_rev_iterator(self.branch, view_revisions,
475
484
view_revisions = _calc_view_revisions(
476
485
self.branch, self.start_rev_id, self.end_rev_id,
477
rqst.get('direction'), generate_merge_revisions=True)
486
rqst.get('direction'), generate_merge_revisions=True,
487
exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
478
488
if not isinstance(view_revisions, list):
479
489
view_revisions = list(view_revisions)
480
490
view_revisions = _filter_revisions_touching_file_id(self.branch,
487
497
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
488
generate_merge_revisions, delayed_graph_generation=False):
498
generate_merge_revisions,
499
delayed_graph_generation=False,
500
exclude_common_ancestry=False,
489
502
"""Calculate the revisions to view.
491
504
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
492
505
a list of the same tuples.
507
if (exclude_common_ancestry and start_rev_id == end_rev_id):
508
raise errors.BzrCommandError(
509
'--exclude-common-ancestry requires two different revisions')
494
510
if direction not in ('reverse', 'forward'):
495
511
raise ValueError('invalid direction %r' % direction)
496
512
br_revno, br_rev_id = branch.last_revision_info()
511
527
iter_revs = reversed(iter_revs)
513
529
iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
514
direction, delayed_graph_generation)
530
direction, delayed_graph_generation,
531
exclude_common_ancestry)
515
532
if direction == 'forward':
516
533
iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
544
561
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
545
delayed_graph_generation):
562
delayed_graph_generation,
563
exclude_common_ancestry=False):
546
564
# On large trees, generating the merge graph can take 30-60 seconds
547
565
# so we delay doing it until a merge is detected, incrementally
548
566
# returning initial (non-merge) revisions while we can.
594
612
# indented at the end seems slightly nicer in that case.
595
613
view_revisions = chain(iter(initial_revisions),
596
614
_graph_view_revisions(branch, start_rev_id, end_rev_id,
597
rebase_initial_depths=(direction == 'reverse')))
615
rebase_initial_depths=(direction == 'reverse'),
616
exclude_common_ancestry=exclude_common_ancestry))
598
617
return view_revisions
661
680
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
662
rebase_initial_depths=True):
681
rebase_initial_depths=True,
682
exclude_common_ancestry=False):
663
683
"""Calculate revisions to view including merges, newest to oldest.
665
685
:param branch: the branch
669
689
revision is found?
670
690
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
692
if exclude_common_ancestry:
693
stop_rule = 'with-merges-without-common-ancestry'
695
stop_rule = 'with-merges'
672
696
view_revisions = branch.iter_merge_sorted_revisions(
673
697
start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
674
stop_rule="with-merges")
675
699
if not rebase_initial_depths:
676
700
for (rev_id, merge_depth, revno, end_of_merge
677
701
) in view_revisions:
1318
1342
def __init__(self, to_file, show_ids=False, show_timezone='original',
1319
1343
delta_format=None, levels=None, show_advice=False,
1320
to_exact_file=None):
1344
to_exact_file=None, author_list_handler=None):
1321
1345
"""Create a LogFormatter.
1323
1347
:param to_file: the file to output to
1331
1355
let the log formatter decide.
1332
1356
:param show_advice: whether to show advice at the end of the
1358
:param author_list_handler: callable generating a list of
1359
authors to display for a given revision
1335
1361
self.to_file = to_file
1336
1362
# 'exact' stream used to show diff, it should print content 'as is'
1390
1417
def short_author(self, rev):
1391
name, address = config.parse_username(rev.get_apparent_authors()[0])
1418
return self.authors(rev, 'first', short=True, sep=', ')
1420
def authors(self, rev, who, short=False, sep=None):
1421
"""Generate list of authors, taking --authors option into account.
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
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.
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
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)
1444
for i in range(len(names)):
1445
name, address = config.parse_username(names[i])
1451
names = sep.join(names)
1396
1454
def merge_marker(self, revision):
1397
1455
"""Get the merge marker to include in the output or '' if none."""
1499
1557
lines.extend(self.custom_properties(revision.rev))
1501
1559
committer = revision.rev.committer
1502
authors = revision.rev.get_apparent_authors()
1560
authors = self.authors(revision.rev, 'all')
1503
1561
if authors != [committer]:
1504
1562
lines.append('author: %s' % (", ".join(authors),))
1505
1563
lines.append('committer: %s' % (committer,))
1679
1737
self.show_timezone,
1680
1738
date_fmt='%Y-%m-%d',
1681
1739
show_offset=False)
1682
committer_str = revision.rev.get_apparent_authors()[0].replace (' <', ' <')
1740
committer_str = self.authors(revision.rev, 'first', sep=', ')
1741
committer_str = committer_str.replace(' <', ' <')
1683
1742
to_file.write('%s %s\n\n' % (date_str,committer_str))
1685
1744
if revision.delta is not None and revision.delta.has_changed():
1750
1809
raise errors.BzrCommandError("unknown log formatter: %r" % name)
1812
def author_list_all(rev):
1813
return rev.get_apparent_authors()[:]
1816
def author_list_first(rev):
1817
lst = rev.get_apparent_authors()
1824
def author_list_committer(rev):
1825
return [rev.committer]
1828
author_list_registry = registry.Registry()
1830
author_list_registry.register('all', author_list_all,
1833
author_list_registry.register('first', author_list_first,
1836
author_list_registry.register('committer', author_list_committer,
1753
1840
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1754
1841
# deprecated; for compatibility
1755
1842
lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)