385
384
:return: An iterator yielding LogRevision objects.
388
levels = rqst.get('levels')
389
limit = rqst.get('limit')
390
diff_type = rqst.get('diff_type')
392
388
revision_iterator = self._create_log_revision_iterator()
393
389
for revs in revision_iterator:
394
390
for (rev_id, revno, merge_depth), rev, delta in revs:
395
391
# 0 levels means show everything; merge_depth counts from 0
392
levels = rqst.get('levels')
396
393
if levels != 0 and merge_depth >= levels:
398
if diff_type is None:
401
diff = self._format_diff(rev, rev_id, diff_type)
395
diff = self._format_diff(rev, rev_id)
402
396
yield LogRevision(rev, revno, merge_depth, delta,
403
397
self.rev_tag_dict.get(rev_id), diff)
398
limit = rqst.get('limit')
406
401
if log_count >= limit:
409
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:
410
408
repo = self.branch.repository
411
409
if len(rev.parent_ids) == 0:
412
410
ancestor_id = _mod_revision.NULL_REVISION
1293
1291
preferred_levels = 0
1295
1293
def __init__(self, to_file, show_ids=False, show_timezone='original',
1296
delta_format=None, levels=None, show_advice=False,
1297
to_exact_file=None):
1294
delta_format=None, levels=None, show_advice=False):
1298
1295
"""Create a LogFormatter.
1300
1297
:param to_file: the file to output to
1301
:param to_exact_file: if set, gives an output stream to which
1302
non-Unicode diffs are written.
1303
1298
:param show_ids: if True, revision-ids are to be displayed
1304
1299
:param show_timezone: the timezone to use
1305
1300
:param delta_format: the level of delta information to display
1381
def show_properties(self, revision, indent):
1382
"""Displays the custom properties returned by each registered handler.
1384
If a registered handler raises an error it is propagated.
1386
for line in self.custom_properties(revision):
1387
self.to_file.write("%s%s\n" % (indent, line))
1389
def custom_properties(self, revision):
1390
"""Format the custom properties returned by each registered handler.
1392
If a registered handler raises an error it is propagated.
1394
:return: a list of formatted lines (excluding trailing newlines)
1396
lines = self._foreign_info_properties(revision)
1397
for key, handler in properties_handler_registry.iteritems():
1398
lines.extend(self._format_properties(handler(revision)))
1401
def _foreign_info_properties(self, rev):
1370
def show_foreign_info(self, rev, indent):
1402
1371
"""Custom log displayer for foreign revision identifiers.
1404
1373
:param rev: Revision object.
1406
1375
# Revision comes directly from a foreign repository
1407
1376
if isinstance(rev, foreign.ForeignRevision):
1408
return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
1377
self._write_properties(indent, rev.mapping.vcs.show_foreign_revid(
1410
1381
# Imported foreign revision revision ids always contain :
1411
1382
if not ":" in rev.revision_id:
1414
1385
# Revision was once imported from a foreign repository
1416
1387
foreign_revid, mapping = \
1417
1388
foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
1418
1389
except errors.InvalidRevisionId:
1421
return self._format_properties(
1392
self._write_properties(indent,
1422
1393
mapping.vcs.show_foreign_revid(foreign_revid))
1424
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):
1426
1404
for key, value in properties.items():
1427
lines.append(key + ': ' + value)
1405
self.to_file.write(indent + key + ': ' + value + '\n')
1430
1407
def show_diff(self, to_file, diff, indent):
1431
1408
for l in diff.rstrip().split('\n'):
1432
1409
to_file.write(indent + '%s\n' % (l,))
1435
# Separator between revisions in long format
1436
_LONG_SEP = '-' * 60
1439
1412
class LongLogFormatter(LogFormatter):
1441
1414
supports_merge_revisions = True
1444
1417
supports_tags = True
1445
1418
supports_diff = True
1447
def __init__(self, *args, **kwargs):
1448
super(LongLogFormatter, self).__init__(*args, **kwargs)
1449
if self.show_timezone == 'original':
1450
self.date_string = self._date_string_original_timezone
1452
self.date_string = self._date_string_with_timezone
1454
def _date_string_with_timezone(self, rev):
1455
return format_date(rev.timestamp, rev.timezone or 0,
1458
def _date_string_original_timezone(self, rev):
1459
return format_date_with_offset_in_original_timezone(rev.timestamp,
1462
1420
def log_revision(self, revision):
1463
1421
"""Log a revision, either merged or not."""
1464
1422
indent = ' ' * revision.merge_depth
1423
to_file = self.to_file
1424
to_file.write(indent + '-' * 60 + '\n')
1466
1425
if revision.revno is not None:
1467
lines.append('revno: %s%s' % (revision.revno,
1426
to_file.write(indent + 'revno: %s%s\n' % (revision.revno,
1468
1427
self.merge_marker(revision)))
1469
1428
if revision.tags:
1470
lines.append('tags: %s' % (', '.join(revision.tags)))
1429
to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
1471
1430
if self.show_ids:
1472
lines.append('revision-id: %s' % (revision.rev.revision_id,))
1431
to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
1473
1433
for parent_id in revision.rev.parent_ids:
1474
lines.append('parent: %s' % (parent_id,))
1475
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)
1477
1438
committer = revision.rev.committer
1478
1439
authors = revision.rev.get_apparent_authors()
1479
1440
if authors != [committer]:
1480
lines.append('author: %s' % (", ".join(authors),))
1481
lines.append('committer: %s' % (committer,))
1441
to_file.write(indent + 'author: %s\n' % (", ".join(authors),))
1442
to_file.write(indent + 'committer: %s\n' % (committer,))
1483
1444
branch_nick = revision.rev.properties.get('branch-nick', None)
1484
1445
if branch_nick is not None:
1485
lines.append('branch nick: %s' % (branch_nick,))
1487
lines.append('timestamp: %s' % (self.date_string(revision.rev),))
1489
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')
1490
1454
if not revision.rev.message:
1491
lines.append(' (no message)')
1455
to_file.write(indent + ' (no message)\n')
1493
1457
message = revision.rev.message.rstrip('\r\n')
1494
1458
for l in message.split('\n'):
1495
lines.append(' %s' % (l,))
1497
# Dump the output, appending the delta and diff if requested
1498
to_file = self.to_file
1499
to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1459
to_file.write(indent + ' %s\n' % (l,))
1500
1460
if revision.delta is not None:
1501
1461
# We don't respect delta_format for compatibility
1502
1462
revision.delta.show(to_file, self.show_ids, indent=indent,
1503
1463
short_status=False)
1504
1464
if revision.diff is not None:
1505
1465
to_file.write(indent + 'diff:\n')
1507
1466
# Note: we explicitly don't indent the diff (relative to the
1508
1467
# revision information) so that the output can be fed to patch -p0
1509
1468
self.show_diff(self.to_exact_file, revision.diff, indent)
1510
self.to_exact_file.flush()
1512
1470
def get_advice_separator(self):
1513
1471
"""Get the text separating the log from the closing advice."""
1585
1544
def __init__(self, *args, **kwargs):
1586
1545
super(LineLogFormatter, self).__init__(*args, **kwargs)
1587
width = terminal_width()
1588
if width is not None:
1589
# we need one extra space for terminals that wrap on last char
1591
self._max_chars = width
1546
self._max_chars = terminal_width() - 1
1593
1548
def truncate(self, str, max_len):
1594
if max_len is None or len(str) <= max_len:
1549
if len(str) <= max_len:
1596
return str[:max_len-3] + '...'
1551
return str[:max_len-3]+'...'
1598
1553
def date_string(self, rev):
1599
1554
return format_date(rev.timestamp, rev.timezone or 0,
1981
1936
properties_handler_registry = registry.Registry()
1983
# Use the properties handlers to print out bug information if available
1984
def _bugs_properties_handler(revision):
1985
if revision.properties.has_key('bugs'):
1986
bug_lines = revision.properties['bugs'].split('\n')
1987
bug_rows = [line.split(' ', 1) for line in bug_lines]
1988
fixed_bug_urls = [row[0] for row in bug_rows if
1989
len(row) > 1 and row[1] == 'fixed']
1992
return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
1995
properties_handler_registry.register('bugs_properties_handler',
1996
_bugs_properties_handler)
1999
1939
# adapters which revision ids to log are filtered. When log is called, the
2000
1940
# log_rev_iterator is adapted through each of these factory methods.