384
389
:return: An iterator yielding LogRevision objects.
392
levels = rqst.get('levels')
393
limit = rqst.get('limit')
394
diff_type = rqst.get('diff_type')
388
396
revision_iterator = self._create_log_revision_iterator()
389
397
for revs in revision_iterator:
390
398
for (rev_id, revno, merge_depth), rev, delta in revs:
391
399
# 0 levels means show everything; merge_depth counts from 0
392
levels = rqst.get('levels')
393
400
if levels != 0 and merge_depth >= levels:
395
diff = self._format_diff(rev, rev_id)
402
if diff_type is None:
405
diff = self._format_diff(rev, rev_id, diff_type)
396
406
yield LogRevision(rev, revno, merge_depth, delta,
397
407
self.rev_tag_dict.get(rev_id), diff)
398
limit = rqst.get('limit')
401
410
if log_count >= limit:
404
def _format_diff(self, rev, rev_id):
405
diff_type = self.rqst.get('diff_type')
406
if diff_type is None:
413
def _format_diff(self, rev, rev_id, diff_type):
408
414
repo = self.branch.repository
409
415
if len(rev.parent_ids) == 0:
410
416
ancestor_id = _mod_revision.NULL_REVISION
530
536
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
531
delayed_graph_generation):
537
delayed_graph_generation):
532
538
# On large trees, generating the merge graph can take 30-60 seconds
533
539
# so we delay doing it until a merge is detected, incrementally
534
540
# returning initial (non-merge) revisions while we can.
542
# The above is only true for old formats (<= 0.92), for newer formats, a
543
# couple of seconds only should be needed to load the whole graph and the
544
# other graph operations needed are even faster than that -- vila 100201
535
545
initial_revisions = []
536
546
if delayed_graph_generation:
538
for rev_id, revno, depth in \
539
_linear_view_revisions(branch, start_rev_id, end_rev_id):
548
for rev_id, revno, depth in _linear_view_revisions(
549
branch, start_rev_id, end_rev_id):
540
550
if _has_merges(branch, rev_id):
551
# The end_rev_id can be nested down somewhere. We need an
552
# explicit ancestry check. There is an ambiguity here as we
553
# may not raise _StartNotLinearAncestor for a revision that
554
# is an ancestor but not a *linear* one. But since we have
555
# loaded the graph to do the check (or calculate a dotted
556
# revno), we may as well accept to show the log... We need
557
# the check only if start_rev_id is not None as all
558
# revisions have _mod_revision.NULL_REVISION as an ancestor
560
graph = branch.repository.get_graph()
561
if (start_rev_id is not None
562
and not graph.is_ancestor(start_rev_id, end_rev_id)):
563
raise _StartNotLinearAncestor()
564
# Since we collected the revisions so far, we need to
541
566
end_rev_id = rev_id
662
692
depth_adjustment = merge_depth
663
693
if depth_adjustment:
664
694
if merge_depth < depth_adjustment:
695
# From now on we reduce the depth adjustement, this can be
696
# surprising for users. The alternative requires two passes
697
# which breaks the fast display of the first revision
665
699
depth_adjustment = merge_depth
666
700
merge_depth -= depth_adjustment
667
701
yield rev_id, '.'.join(map(str, revno)), merge_depth
704
@deprecated_function(deprecated_in((2, 2, 0)))
670
705
def calculate_view_revisions(branch, start_revision, end_revision, direction,
671
706
specific_fileid, generate_merge_revisions):
672
707
"""Calculate the revisions to view.
1291
1320
preferred_levels = 0
1293
1322
def __init__(self, to_file, show_ids=False, show_timezone='original',
1294
delta_format=None, levels=None, show_advice=False):
1323
delta_format=None, levels=None, show_advice=False,
1324
to_exact_file=None):
1295
1325
"""Create a LogFormatter.
1297
1327
:param to_file: the file to output to
1328
:param to_exact_file: if set, gives an output stream to which
1329
non-Unicode diffs are written.
1298
1330
:param show_ids: if True, revision-ids are to be displayed
1299
1331
:param show_timezone: the timezone to use
1300
1332
:param delta_format: the level of delta information to display
1370
def show_foreign_info(self, rev, indent):
1408
def show_properties(self, revision, indent):
1409
"""Displays the custom properties returned by each registered handler.
1411
If a registered handler raises an error it is propagated.
1413
for line in self.custom_properties(revision):
1414
self.to_file.write("%s%s\n" % (indent, line))
1416
def custom_properties(self, revision):
1417
"""Format the custom properties returned by each registered handler.
1419
If a registered handler raises an error it is propagated.
1421
:return: a list of formatted lines (excluding trailing newlines)
1423
lines = self._foreign_info_properties(revision)
1424
for key, handler in properties_handler_registry.iteritems():
1425
lines.extend(self._format_properties(handler(revision)))
1428
def _foreign_info_properties(self, rev):
1371
1429
"""Custom log displayer for foreign revision identifiers.
1373
1431
:param rev: Revision object.
1375
1433
# Revision comes directly from a foreign repository
1376
1434
if isinstance(rev, foreign.ForeignRevision):
1377
self._write_properties(indent, rev.mapping.vcs.show_foreign_revid(
1435
return self._format_properties(
1436
rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
1381
1438
# Imported foreign revision revision ids always contain :
1382
1439
if not ":" in rev.revision_id:
1385
1442
# Revision was once imported from a foreign repository
1387
1444
foreign_revid, mapping = \
1388
1445
foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
1389
1446
except errors.InvalidRevisionId:
1392
self._write_properties(indent,
1449
return self._format_properties(
1393
1450
mapping.vcs.show_foreign_revid(foreign_revid))
1395
def show_properties(self, revision, indent):
1396
"""Displays the custom properties returned by each registered handler.
1398
If a registered handler raises an error it is propagated.
1400
for key, handler in properties_handler_registry.iteritems():
1401
self._write_properties(indent, handler(revision))
1403
def _write_properties(self, indent, properties):
1452
def _format_properties(self, properties):
1404
1454
for key, value in properties.items():
1405
self.to_file.write(indent + key + ': ' + value + '\n')
1455
lines.append(key + ': ' + value)
1407
1458
def show_diff(self, to_file, diff, indent):
1408
1459
for l in diff.rstrip().split('\n'):
1409
1460
to_file.write(indent + '%s\n' % (l,))
1463
# Separator between revisions in long format
1464
_LONG_SEP = '-' * 60
1412
1467
class LongLogFormatter(LogFormatter):
1414
1469
supports_merge_revisions = True
1417
1472
supports_tags = True
1418
1473
supports_diff = True
1475
def __init__(self, *args, **kwargs):
1476
super(LongLogFormatter, self).__init__(*args, **kwargs)
1477
if self.show_timezone == 'original':
1478
self.date_string = self._date_string_original_timezone
1480
self.date_string = self._date_string_with_timezone
1482
def _date_string_with_timezone(self, rev):
1483
return format_date(rev.timestamp, rev.timezone or 0,
1486
def _date_string_original_timezone(self, rev):
1487
return format_date_with_offset_in_original_timezone(rev.timestamp,
1420
1490
def log_revision(self, revision):
1421
1491
"""Log a revision, either merged or not."""
1422
1492
indent = ' ' * revision.merge_depth
1423
to_file = self.to_file
1424
to_file.write(indent + '-' * 60 + '\n')
1425
1494
if revision.revno is not None:
1426
to_file.write(indent + 'revno: %s%s\n' % (revision.revno,
1495
lines.append('revno: %s%s' % (revision.revno,
1427
1496
self.merge_marker(revision)))
1428
1497
if revision.tags:
1429
to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
1498
lines.append('tags: %s' % (', '.join(revision.tags)))
1430
1499
if self.show_ids:
1431
to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
1500
lines.append('revision-id: %s' % (revision.rev.revision_id,))
1433
1501
for parent_id in revision.rev.parent_ids:
1434
to_file.write(indent + 'parent: %s\n' % (parent_id,))
1435
self.show_foreign_info(revision.rev, indent)
1436
self.show_properties(revision.rev, indent)
1502
lines.append('parent: %s' % (parent_id,))
1503
lines.extend(self.custom_properties(revision.rev))
1438
1505
committer = revision.rev.committer
1439
1506
authors = revision.rev.get_apparent_authors()
1440
1507
if authors != [committer]:
1441
to_file.write(indent + 'author: %s\n' % (", ".join(authors),))
1442
to_file.write(indent + 'committer: %s\n' % (committer,))
1508
lines.append('author: %s' % (", ".join(authors),))
1509
lines.append('committer: %s' % (committer,))
1444
1511
branch_nick = revision.rev.properties.get('branch-nick', None)
1445
1512
if branch_nick is not None:
1446
to_file.write(indent + 'branch nick: %s\n' % (branch_nick,))
1448
date_str = format_date(revision.rev.timestamp,
1449
revision.rev.timezone or 0,
1451
to_file.write(indent + 'timestamp: %s\n' % (date_str,))
1453
to_file.write(indent + 'message:\n')
1513
lines.append('branch nick: %s' % (branch_nick,))
1515
lines.append('timestamp: %s' % (self.date_string(revision.rev),))
1517
lines.append('message:')
1454
1518
if not revision.rev.message:
1455
to_file.write(indent + ' (no message)\n')
1519
lines.append(' (no message)')
1457
1521
message = revision.rev.message.rstrip('\r\n')
1458
1522
for l in message.split('\n'):
1459
to_file.write(indent + ' %s\n' % (l,))
1523
lines.append(' %s' % (l,))
1525
# Dump the output, appending the delta and diff if requested
1526
to_file = self.to_file
1527
to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1460
1528
if revision.delta is not None:
1461
# We don't respect delta_format for compatibility
1462
revision.delta.show(to_file, self.show_ids, indent=indent,
1529
# Use the standard status output to display changes
1530
from bzrlib.delta import report_delta
1531
report_delta(to_file, revision.delta, short_status=False,
1532
show_ids=self.show_ids, indent=indent)
1464
1533
if revision.diff is not None:
1465
1534
to_file.write(indent + 'diff:\n')
1466
1536
# Note: we explicitly don't indent the diff (relative to the
1467
1537
# revision information) so that the output can be fed to patch -p0
1468
1538
self.show_diff(self.to_exact_file, revision.diff, indent)
1539
self.to_exact_file.flush()
1470
1541
def get_advice_separator(self):
1471
1542
"""Get the text separating the log from the closing advice."""
1528
1598
to_file.write(indent + offset + '%s\n' % (l,))
1530
1600
if revision.delta is not None:
1531
revision.delta.show(to_file, self.show_ids, indent=indent + offset,
1532
short_status=self.delta_format==1)
1601
# Use the standard status output to display changes
1602
from bzrlib.delta import report_delta
1603
report_delta(to_file, revision.delta,
1604
short_status=self.delta_format==1,
1605
show_ids=self.show_ids, indent=indent + offset)
1533
1606
if revision.diff is not None:
1534
1607
self.show_diff(self.to_exact_file, revision.diff, ' ')
1535
1608
to_file.write('\n')
1846
1923
:return: (branch, info_list, start_rev_info, end_rev_info) where
1847
1924
info_list is a list of (relative_path, file_id, kind) tuples where
1848
1925
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1926
branch will be read-locked.
1850
1928
from builtins import _get_revision_range, safe_relpath_files
1851
1929
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
1852
1931
# XXX: It's damn messy converting a list of paths to relative paths when
1853
1932
# those paths might be deleted ones, they might be on a case-insensitive
1854
1933
# filesystem and/or they might be in silly locations (like another branch).
1934
2013
properties_handler_registry = registry.Registry()
2015
# Use the properties handlers to print out bug information if available
2016
def _bugs_properties_handler(revision):
2017
if revision.properties.has_key('bugs'):
2018
bug_lines = revision.properties['bugs'].split('\n')
2019
bug_rows = [line.split(' ', 1) for line in bug_lines]
2020
fixed_bug_urls = [row[0] for row in bug_rows if
2021
len(row) > 1 and row[1] == 'fixed']
2024
return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
2027
properties_handler_registry.register('bugs_properties_handler',
2028
_bugs_properties_handler)
1937
2031
# adapters which revision ids to log are filtered. When log is called, the
1938
2032
# log_rev_iterator is adapted through each of these factory methods.