389
384
:return: An iterator yielding LogRevision objects.
392
levels = rqst.get('levels')
393
limit = rqst.get('limit')
394
diff_type = rqst.get('diff_type')
396
388
revision_iterator = self._create_log_revision_iterator()
397
389
for revs in revision_iterator:
398
390
for (rev_id, revno, merge_depth), rev, delta in revs:
399
391
# 0 levels means show everything; merge_depth counts from 0
392
levels = rqst.get('levels')
400
393
if levels != 0 and merge_depth >= levels:
402
if diff_type is None:
405
diff = self._format_diff(rev, rev_id, diff_type)
395
diff = self._format_diff(rev, rev_id)
406
396
yield LogRevision(rev, revno, merge_depth, delta,
407
397
self.rev_tag_dict.get(rev_id), diff)
398
limit = rqst.get('limit')
410
401
if log_count >= limit:
413
def _format_diff(self, rev, rev_id, diff_type):
404
def _format_diff(self, rev, rev_id):
405
diff_type = self.rqst.get('diff_type')
406
if diff_type is None:
414
408
repo = self.branch.repository
415
409
if len(rev.parent_ids) == 0:
416
410
ancestor_id = _mod_revision.NULL_REVISION
536
530
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
537
delayed_graph_generation):
531
delayed_graph_generation):
538
532
# On large trees, generating the merge graph can take 30-60 seconds
539
533
# so we delay doing it until a merge is detected, incrementally
540
534
# 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
545
535
initial_revisions = []
546
536
if delayed_graph_generation:
548
for rev_id, revno, depth in _linear_view_revisions(
549
branch, start_rev_id, end_rev_id):
538
for rev_id, revno, depth in \
539
_linear_view_revisions(branch, start_rev_id, end_rev_id):
550
540
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...
558
graph = branch.repository.get_graph()
559
if not graph.is_ancestor(start_rev_id, end_rev_id):
560
raise _StartNotLinearAncestor()
561
541
end_rev_id = rev_id
684
662
depth_adjustment = merge_depth
685
663
if depth_adjustment:
686
664
if merge_depth < depth_adjustment:
687
# From now on we reduce the depth adjustement, this can be
688
# surprising for users. The alternative requires two passes
689
# which breaks the fast display of the first revision
691
665
depth_adjustment = merge_depth
692
666
merge_depth -= depth_adjustment
693
667
yield rev_id, '.'.join(map(str, revno)), merge_depth
696
@deprecated_function(deprecated_in((2, 2, 0)))
697
670
def calculate_view_revisions(branch, start_revision, end_revision, direction,
698
671
specific_fileid, generate_merge_revisions):
699
672
"""Calculate the revisions to view.
1185
@deprecated_function(deprecated_in((2, 2, 0)))
1186
1162
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
1187
1163
include_merges=True):
1188
1164
"""Produce an iterator of revisions to show
1189
1165
:return: an iterator of (revision_id, revno, merge_depth)
1190
1166
(if there is no revno for a revision, None is supplied)
1168
# This method is no longer called by the main code path.
1169
# It is retained for API compatibility and may be deprecated
1170
# soon. IGC 20090127
1192
1171
if not include_merges:
1193
1172
revision_ids = mainline_revs[1:]
1194
1173
if direction == 'reverse':
1312
1291
preferred_levels = 0
1314
1293
def __init__(self, to_file, show_ids=False, show_timezone='original',
1315
delta_format=None, levels=None, show_advice=False,
1316
to_exact_file=None):
1294
delta_format=None, levels=None, show_advice=False):
1317
1295
"""Create a LogFormatter.
1319
1297
:param to_file: the file to output to
1320
:param to_exact_file: if set, gives an output stream to which
1321
non-Unicode diffs are written.
1322
1298
:param show_ids: if True, revision-ids are to be displayed
1323
1299
:param show_timezone: the timezone to use
1324
1300
:param delta_format: the level of delta information to display
1400
def show_properties(self, revision, indent):
1401
"""Displays the custom properties returned by each registered handler.
1403
If a registered handler raises an error it is propagated.
1405
for line in self.custom_properties(revision):
1406
self.to_file.write("%s%s\n" % (indent, line))
1408
def custom_properties(self, revision):
1409
"""Format the custom properties returned by each registered handler.
1411
If a registered handler raises an error it is propagated.
1413
:return: a list of formatted lines (excluding trailing newlines)
1415
lines = self._foreign_info_properties(revision)
1416
for key, handler in properties_handler_registry.iteritems():
1417
lines.extend(self._format_properties(handler(revision)))
1420
def _foreign_info_properties(self, rev):
1370
def show_foreign_info(self, rev, indent):
1421
1371
"""Custom log displayer for foreign revision identifiers.
1423
1373
:param rev: Revision object.
1425
1375
# Revision comes directly from a foreign repository
1426
1376
if isinstance(rev, foreign.ForeignRevision):
1427
return self._format_properties(rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
1377
self._write_properties(indent, rev.mapping.vcs.show_foreign_revid(
1429
1381
# Imported foreign revision revision ids always contain :
1430
1382
if not ":" in rev.revision_id:
1433
1385
# Revision was once imported from a foreign repository
1435
1387
foreign_revid, mapping = \
1436
1388
foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
1437
1389
except errors.InvalidRevisionId:
1440
return self._format_properties(
1392
self._write_properties(indent,
1441
1393
mapping.vcs.show_foreign_revid(foreign_revid))
1443
def _format_properties(self, properties):
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):
1445
1404
for key, value in properties.items():
1446
lines.append(key + ': ' + value)
1405
self.to_file.write(indent + key + ': ' + value + '\n')
1449
1407
def show_diff(self, to_file, diff, indent):
1450
1408
for l in diff.rstrip().split('\n'):
1451
1409
to_file.write(indent + '%s\n' % (l,))
1454
# Separator between revisions in long format
1455
_LONG_SEP = '-' * 60
1458
1412
class LongLogFormatter(LogFormatter):
1460
1414
supports_merge_revisions = True
1463
1417
supports_tags = True
1464
1418
supports_diff = True
1466
def __init__(self, *args, **kwargs):
1467
super(LongLogFormatter, self).__init__(*args, **kwargs)
1468
if self.show_timezone == 'original':
1469
self.date_string = self._date_string_original_timezone
1471
self.date_string = self._date_string_with_timezone
1473
def _date_string_with_timezone(self, rev):
1474
return format_date(rev.timestamp, rev.timezone or 0,
1477
def _date_string_original_timezone(self, rev):
1478
return format_date_with_offset_in_original_timezone(rev.timestamp,
1481
1420
def log_revision(self, revision):
1482
1421
"""Log a revision, either merged or not."""
1483
1422
indent = ' ' * revision.merge_depth
1423
to_file = self.to_file
1424
to_file.write(indent + '-' * 60 + '\n')
1485
1425
if revision.revno is not None:
1486
lines.append('revno: %s%s' % (revision.revno,
1426
to_file.write(indent + 'revno: %s%s\n' % (revision.revno,
1487
1427
self.merge_marker(revision)))
1488
1428
if revision.tags:
1489
lines.append('tags: %s' % (', '.join(revision.tags)))
1429
to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
1490
1430
if self.show_ids:
1491
lines.append('revision-id: %s' % (revision.rev.revision_id,))
1431
to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
1492
1433
for parent_id in revision.rev.parent_ids:
1493
lines.append('parent: %s' % (parent_id,))
1494
lines.extend(self.custom_properties(revision.rev))
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)
1496
1438
committer = revision.rev.committer
1497
1439
authors = revision.rev.get_apparent_authors()
1498
1440
if authors != [committer]:
1499
lines.append('author: %s' % (", ".join(authors),))
1500
lines.append('committer: %s' % (committer,))
1441
to_file.write(indent + 'author: %s\n' % (", ".join(authors),))
1442
to_file.write(indent + 'committer: %s\n' % (committer,))
1502
1444
branch_nick = revision.rev.properties.get('branch-nick', None)
1503
1445
if branch_nick is not None:
1504
lines.append('branch nick: %s' % (branch_nick,))
1506
lines.append('timestamp: %s' % (self.date_string(revision.rev),))
1508
lines.append('message:')
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')
1509
1454
if not revision.rev.message:
1510
lines.append(' (no message)')
1455
to_file.write(indent + ' (no message)\n')
1512
1457
message = revision.rev.message.rstrip('\r\n')
1513
1458
for l in message.split('\n'):
1514
lines.append(' %s' % (l,))
1516
# Dump the output, appending the delta and diff if requested
1517
to_file = self.to_file
1518
to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1459
to_file.write(indent + ' %s\n' % (l,))
1519
1460
if revision.delta is not None:
1520
1461
# We don't respect delta_format for compatibility
1521
1462
revision.delta.show(to_file, self.show_ids, indent=indent,
1522
1463
short_status=False)
1523
1464
if revision.diff is not None:
1524
1465
to_file.write(indent + 'diff:\n')
1526
1466
# Note: we explicitly don't indent the diff (relative to the
1527
1467
# revision information) so that the output can be fed to patch -p0
1528
1468
self.show_diff(self.to_exact_file, revision.diff, indent)
1529
self.to_exact_file.flush()
1531
1470
def get_advice_separator(self):
1532
1471
"""Get the text separating the log from the closing advice."""
1604
1544
def __init__(self, *args, **kwargs):
1605
1545
super(LineLogFormatter, self).__init__(*args, **kwargs)
1606
width = terminal_width()
1607
if width is not None:
1608
# we need one extra space for terminals that wrap on last char
1610
self._max_chars = width
1546
self._max_chars = terminal_width() - 1
1612
1548
def truncate(self, str, max_len):
1613
if max_len is None or len(str) <= max_len:
1549
if len(str) <= max_len:
1615
return str[:max_len-3] + '...'
1551
return str[:max_len-3]+'...'
1617
1553
def date_string(self, rev):
1618
1554
return format_date(rev.timestamp, rev.timezone or 0,
1910
1846
:return: (branch, info_list, start_rev_info, end_rev_info) where
1911
1847
info_list is a list of (relative_path, file_id, kind) tuples where
1912
1848
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1913
branch will be read-locked.
1915
1850
from builtins import _get_revision_range, safe_relpath_files
1916
1851
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
1918
1852
# XXX: It's damn messy converting a list of paths to relative paths when
1919
1853
# those paths might be deleted ones, they might be on a case-insensitive
1920
1854
# filesystem and/or they might be in silly locations (like another branch).
2000
1934
properties_handler_registry = registry.Registry()
2002
# Use the properties handlers to print out bug information if available
2003
def _bugs_properties_handler(revision):
2004
if revision.properties.has_key('bugs'):
2005
bug_lines = revision.properties['bugs'].split('\n')
2006
bug_rows = [line.split(' ', 1) for line in bug_lines]
2007
fixed_bug_urls = [row[0] for row in bug_rows if
2008
len(row) > 1 and row[1] == 'fixed']
2011
return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
2014
properties_handler_registry.register('bugs_properties_handler',
2015
_bugs_properties_handler)
2018
1937
# adapters which revision ids to log are filtered. When log is called, the
2019
1938
# log_rev_iterator is adapted through each of these factory methods.