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...
558
graph = branch.repository.get_graph()
559
if not graph.is_ancestor(start_rev_id, end_rev_id):
560
raise _StartNotLinearAncestor()
541
561
end_rev_id = rev_id
662
684
depth_adjustment = merge_depth
663
685
if depth_adjustment:
664
686
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
665
691
depth_adjustment = merge_depth
666
692
merge_depth -= depth_adjustment
667
693
yield rev_id, '.'.join(map(str, revno)), merge_depth
696
@deprecated_function(deprecated_in((2, 2, 0)))
670
697
def calculate_view_revisions(branch, start_revision, end_revision, direction,
671
698
specific_fileid, generate_merge_revisions):
672
699
"""Calculate the revisions to view.
1185
@deprecated_function(deprecated_in((2, 2, 0)))
1162
1186
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
1163
1187
include_merges=True):
1164
1188
"""Produce an iterator of revisions to show
1165
1189
:return: an iterator of (revision_id, revno, merge_depth)
1166
1190
(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
1171
1192
if not include_merges:
1172
1193
revision_ids = mainline_revs[1:]
1173
1194
if direction == 'reverse':
1291
1312
preferred_levels = 0
1293
1314
def __init__(self, to_file, show_ids=False, show_timezone='original',
1294
delta_format=None, levels=None, show_advice=False):
1315
delta_format=None, levels=None, show_advice=False,
1316
to_exact_file=None):
1295
1317
"""Create a LogFormatter.
1297
1319
: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.
1298
1322
:param show_ids: if True, revision-ids are to be displayed
1299
1323
:param show_timezone: the timezone to use
1300
1324
:param delta_format: the level of delta information to display
1370
def show_foreign_info(self, rev, indent):
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):
1371
1421
"""Custom log displayer for foreign revision identifiers.
1373
1423
:param rev: Revision object.
1375
1425
# Revision comes directly from a foreign repository
1376
1426
if isinstance(rev, foreign.ForeignRevision):
1377
self._write_properties(indent, rev.mapping.vcs.show_foreign_revid(
1427
return self._format_properties(rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
1381
1429
# Imported foreign revision revision ids always contain :
1382
1430
if not ":" in rev.revision_id:
1385
1433
# Revision was once imported from a foreign repository
1387
1435
foreign_revid, mapping = \
1388
1436
foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
1389
1437
except errors.InvalidRevisionId:
1392
self._write_properties(indent,
1440
return self._format_properties(
1393
1441
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):
1443
def _format_properties(self, properties):
1404
1445
for key, value in properties.items():
1405
self.to_file.write(indent + key + ': ' + value + '\n')
1446
lines.append(key + ': ' + value)
1407
1449
def show_diff(self, to_file, diff, indent):
1408
1450
for l in diff.rstrip().split('\n'):
1409
1451
to_file.write(indent + '%s\n' % (l,))
1454
# Separator between revisions in long format
1455
_LONG_SEP = '-' * 60
1412
1458
class LongLogFormatter(LogFormatter):
1414
1460
supports_merge_revisions = True
1417
1463
supports_tags = True
1418
1464
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,
1420
1481
def log_revision(self, revision):
1421
1482
"""Log a revision, either merged or not."""
1422
1483
indent = ' ' * revision.merge_depth
1423
to_file = self.to_file
1424
to_file.write(indent + '-' * 60 + '\n')
1425
1485
if revision.revno is not None:
1426
to_file.write(indent + 'revno: %s%s\n' % (revision.revno,
1486
lines.append('revno: %s%s' % (revision.revno,
1427
1487
self.merge_marker(revision)))
1428
1488
if revision.tags:
1429
to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
1489
lines.append('tags: %s' % (', '.join(revision.tags)))
1430
1490
if self.show_ids:
1431
to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
1491
lines.append('revision-id: %s' % (revision.rev.revision_id,))
1433
1492
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)
1493
lines.append('parent: %s' % (parent_id,))
1494
lines.extend(self.custom_properties(revision.rev))
1438
1496
committer = revision.rev.committer
1439
1497
authors = revision.rev.get_apparent_authors()
1440
1498
if authors != [committer]:
1441
to_file.write(indent + 'author: %s\n' % (", ".join(authors),))
1442
to_file.write(indent + 'committer: %s\n' % (committer,))
1499
lines.append('author: %s' % (", ".join(authors),))
1500
lines.append('committer: %s' % (committer,))
1444
1502
branch_nick = revision.rev.properties.get('branch-nick', None)
1445
1503
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')
1504
lines.append('branch nick: %s' % (branch_nick,))
1506
lines.append('timestamp: %s' % (self.date_string(revision.rev),))
1508
lines.append('message:')
1454
1509
if not revision.rev.message:
1455
to_file.write(indent + ' (no message)\n')
1510
lines.append(' (no message)')
1457
1512
message = revision.rev.message.rstrip('\r\n')
1458
1513
for l in message.split('\n'):
1459
to_file.write(indent + ' %s\n' % (l,))
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)))
1460
1519
if revision.delta is not None:
1461
1520
# We don't respect delta_format for compatibility
1462
1521
revision.delta.show(to_file, self.show_ids, indent=indent,
1463
1522
short_status=False)
1464
1523
if revision.diff is not None:
1465
1524
to_file.write(indent + 'diff:\n')
1466
1526
# Note: we explicitly don't indent the diff (relative to the
1467
1527
# revision information) so that the output can be fed to patch -p0
1468
1528
self.show_diff(self.to_exact_file, revision.diff, indent)
1529
self.to_exact_file.flush()
1470
1531
def get_advice_separator(self):
1471
1532
"""Get the text separating the log from the closing advice."""
1544
1604
def __init__(self, *args, **kwargs):
1545
1605
super(LineLogFormatter, self).__init__(*args, **kwargs)
1546
self._max_chars = terminal_width() - 1
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
1548
1612
def truncate(self, str, max_len):
1549
if len(str) <= max_len:
1613
if max_len is None or len(str) <= max_len:
1551
return str[:max_len-3]+'...'
1615
return str[:max_len-3] + '...'
1553
1617
def date_string(self, rev):
1554
1618
return format_date(rev.timestamp, rev.timezone or 0,
1936
2000
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)
1939
2018
# adapters which revision ids to log are filtered. When log is called, the
1940
2019
# log_rev_iterator is adapted through each of these factory methods.