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
455
464
generate_merge_revisions = rqst.get('levels') != 1
456
465
delayed_graph_generation = not rqst.get('specific_fileids') and (
457
466
rqst.get('limit') or self.start_rev_id or self.end_rev_id)
458
view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
459
self.end_rev_id, rqst.get('direction'), generate_merge_revisions,
460
delayed_graph_generation=delayed_graph_generation)
467
view_revisions = _calc_view_revisions(
468
self.branch, self.start_rev_id, self.end_rev_id,
469
rqst.get('direction'),
470
generate_merge_revisions=generate_merge_revisions,
471
delayed_graph_generation=delayed_graph_generation,
472
exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
462
474
# Apply the other filters
463
475
return make_log_rev_iterator(self.branch, view_revisions,
470
482
# Note that we always generate the merge revisions because
471
483
# filter_revisions_touching_file_id() requires them ...
473
view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
474
self.end_rev_id, rqst.get('direction'), True)
485
view_revisions = _calc_view_revisions(
486
self.branch, self.start_rev_id, self.end_rev_id,
487
rqst.get('direction'), generate_merge_revisions=True,
488
exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
475
489
if not isinstance(view_revisions, list):
476
490
view_revisions = list(view_revisions)
477
491
view_revisions = _filter_revisions_touching_file_id(self.branch,
484
498
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
485
generate_merge_revisions, delayed_graph_generation=False):
499
generate_merge_revisions,
500
delayed_graph_generation=False,
501
exclude_common_ancestry=False,
486
503
"""Calculate the revisions to view.
488
505
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
489
506
a list of the same tuples.
508
if (exclude_common_ancestry and start_rev_id == end_rev_id):
509
raise errors.BzrCommandError(
510
'--exclude-common-ancestry requires two different revisions')
511
if direction not in ('reverse', 'forward'):
512
raise ValueError('invalid direction %r' % direction)
491
513
br_revno, br_rev_id = branch.last_revision_info()
492
514
if br_revno == 0:
495
# If a single revision is requested, check we can handle it
496
generate_single_revision = (end_rev_id and start_rev_id == end_rev_id and
497
(not generate_merge_revisions or not _has_merges(branch, end_rev_id)))
498
if generate_single_revision:
499
return _generate_one_revision(branch, end_rev_id, br_rev_id, br_revno)
501
# If we only want to see linear revisions, we can iterate ...
502
if not generate_merge_revisions:
503
return _generate_flat_revisions(branch, start_rev_id, end_rev_id,
517
if (end_rev_id and start_rev_id == end_rev_id
518
and (not generate_merge_revisions
519
or not _has_merges(branch, end_rev_id))):
520
# If a single revision is requested, check we can handle it
521
iter_revs = _generate_one_revision(branch, end_rev_id, br_rev_id,
523
elif not generate_merge_revisions:
524
# If we only want to see linear revisions, we can iterate ...
525
iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
526
direction, exclude_common_ancestry)
527
if direction == 'forward':
528
iter_revs = reversed(iter_revs)
506
return _generate_all_revisions(branch, start_rev_id, end_rev_id,
507
direction, delayed_graph_generation)
530
iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
531
direction, delayed_graph_generation,
532
exclude_common_ancestry)
533
if direction == 'forward':
534
iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
510
538
def _generate_one_revision(branch, rev_id, br_rev_id, br_revno):
517
545
return [(rev_id, revno_str, 0)]
520
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction):
521
result = _linear_view_revisions(branch, start_rev_id, end_rev_id)
548
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction,
549
exclude_common_ancestry=False):
550
result = _linear_view_revisions(
551
branch, start_rev_id, end_rev_id,
552
exclude_common_ancestry=exclude_common_ancestry)
522
553
# If a start limit was given and it's not obviously an
523
554
# ancestor of the end limit, check it before outputting anything
524
555
if direction == 'forward' or (start_rev_id
528
559
except _StartNotLinearAncestor:
529
560
raise errors.BzrCommandError('Start revision not found in'
530
561
' left-hand history of end revision.')
531
if direction == 'forward':
532
result = reversed(result)
536
565
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
537
delayed_graph_generation):
566
delayed_graph_generation,
567
exclude_common_ancestry=False):
538
568
# On large trees, generating the merge graph can take 30-60 seconds
539
569
# so we delay doing it until a merge is detected, incrementally
540
570
# returning initial (non-merge) revisions while we can.
572
# The above is only true for old formats (<= 0.92), for newer formats, a
573
# couple of seconds only should be needed to load the whole graph and the
574
# other graph operations needed are even faster than that -- vila 100201
541
575
initial_revisions = []
542
576
if delayed_graph_generation:
544
for rev_id, revno, depth in \
545
_linear_view_revisions(branch, start_rev_id, end_rev_id):
578
for rev_id, revno, depth in _linear_view_revisions(
579
branch, start_rev_id, end_rev_id, exclude_common_ancestry):
546
580
if _has_merges(branch, rev_id):
581
# The end_rev_id can be nested down somewhere. We need an
582
# explicit ancestry check. There is an ambiguity here as we
583
# may not raise _StartNotLinearAncestor for a revision that
584
# is an ancestor but not a *linear* one. But since we have
585
# loaded the graph to do the check (or calculate a dotted
586
# revno), we may as well accept to show the log... We need
587
# the check only if start_rev_id is not None as all
588
# revisions have _mod_revision.NULL_REVISION as an ancestor
590
graph = branch.repository.get_graph()
591
if (start_rev_id is not None
592
and not graph.is_ancestor(start_rev_id, end_rev_id)):
593
raise _StartNotLinearAncestor()
594
# Since we collected the revisions so far, we need to
547
596
end_rev_id = rev_id
550
599
initial_revisions.append((rev_id, revno, depth))
552
601
# No merged revisions found
553
if direction == 'reverse':
554
return initial_revisions
555
elif direction == 'forward':
556
return reversed(initial_revisions)
558
raise ValueError('invalid direction %r' % direction)
602
return initial_revisions
559
603
except _StartNotLinearAncestor:
560
604
# A merge was never detected so the lower revision limit can't
561
605
# be nested down somewhere
562
606
raise errors.BzrCommandError('Start revision not found in'
563
607
' history of end revision.')
609
# We exit the loop above because we encounter a revision with merges, from
610
# this revision, we need to switch to _graph_view_revisions.
565
612
# A log including nested merges is required. If the direction is reverse,
566
613
# we rebase the initial merge depths so that the development line is
567
614
# shown naturally, i.e. just like it is for linear logging. We can easily
569
616
# indented at the end seems slightly nicer in that case.
570
617
view_revisions = chain(iter(initial_revisions),
571
618
_graph_view_revisions(branch, start_rev_id, end_rev_id,
572
rebase_initial_depths=direction == 'reverse'))
573
if direction == 'reverse':
574
return view_revisions
575
elif direction == 'forward':
576
# Forward means oldest first, adjusting for depth.
577
view_revisions = reverse_by_depth(list(view_revisions))
578
return _rebase_merge_depth(view_revisions)
580
raise ValueError('invalid direction %r' % direction)
619
rebase_initial_depths=(direction == 'reverse'),
620
exclude_common_ancestry=exclude_common_ancestry))
621
return view_revisions
583
624
def _has_merges(branch, rev_id):
609
def _linear_view_revisions(branch, start_rev_id, end_rev_id):
650
def _linear_view_revisions(branch, start_rev_id, end_rev_id,
651
exclude_common_ancestry=False):
610
652
"""Calculate a sequence of revisions to view, newest to oldest.
612
654
:param start_rev_id: the lower revision-id
613
655
:param end_rev_id: the upper revision-id
656
:param exclude_common_ancestry: Whether the start_rev_id should be part of
657
the iterated revisions.
614
658
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
615
659
:raises _StartNotLinearAncestor: if a start_rev_id is specified but
616
is not found walking the left-hand history
660
is not found walking the left-hand history
618
662
br_revno, br_rev_id = branch.last_revision_info()
619
663
repo = branch.repository
651
697
revision is found?
652
698
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
700
if exclude_common_ancestry:
701
stop_rule = 'with-merges-without-common-ancestry'
703
stop_rule = 'with-merges'
654
704
view_revisions = branch.iter_merge_sorted_revisions(
655
705
start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
656
stop_rule="with-merges")
657
707
if not rebase_initial_depths:
658
708
for (rev_id, merge_depth, revno, end_of_merge
659
709
) in view_revisions:
1372
1424
def short_author(self, rev):
1373
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)
1378
1461
def merge_marker(self, revision):
1379
1462
"""Get the merge marker to include in the output or '' if none."""
1503
1587
to_file = self.to_file
1504
1588
to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1505
1589
if revision.delta is not None:
1506
# We don't respect delta_format for compatibility
1507
revision.delta.show(to_file, self.show_ids, indent=indent,
1590
# Use the standard status output to display changes
1591
from bzrlib.delta import report_delta
1592
report_delta(to_file, revision.delta, short_status=False,
1593
show_ids=self.show_ids, indent=indent)
1509
1594
if revision.diff is not None:
1510
1595
to_file.write(indent + 'diff:\n')
1511
1596
to_file.flush()
1574
1659
to_file.write(indent + offset + '%s\n' % (l,))
1576
1661
if revision.delta is not None:
1577
revision.delta.show(to_file, self.show_ids, indent=indent + offset,
1578
short_status=self.delta_format==1)
1662
# Use the standard status output to display changes
1663
from bzrlib.delta import report_delta
1664
report_delta(to_file, revision.delta,
1665
short_status=self.delta_format==1,
1666
show_ids=self.show_ids, indent=indent + offset)
1579
1667
if revision.diff is not None:
1580
1668
self.show_diff(self.to_exact_file, revision.diff, ' ')
1581
1669
to_file.write('\n')
1727
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,
1730
1847
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1731
1848
# deprecated; for compatibility
1732
1849
lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1893
2010
:param file_list: the list of paths given on the command line;
1894
2011
the first of these can be a branch location or a file path,
1895
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.
1896
2015
:return: (branch, info_list, start_rev_info, end_rev_info) where
1897
2016
info_list is a list of (relative_path, file_id, kind) tuples where
1898
2017
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1899
2018
branch will be read-locked.
1901
from builtins import _get_revision_range, safe_relpath_files
2020
from builtins import _get_revision_range
1902
2021
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2022
add_cleanup(b.lock_read().unlock)
1904
2023
# XXX: It's damn messy converting a list of paths to relative paths when
1905
2024
# those paths might be deleted ones, they might be on a case-insensitive
1906
2025
# filesystem and/or they might be in silly locations (like another branch).