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
662
670
depth_adjustment = merge_depth
663
671
if depth_adjustment:
664
672
if merge_depth < depth_adjustment:
673
# From now on we reduce the depth adjustement, this can be
674
# surprising for users. The alternative requires two passes
675
# which breaks the fast display of the first revision
665
677
depth_adjustment = merge_depth
666
678
merge_depth -= depth_adjustment
667
679
yield rev_id, '.'.join(map(str, revno)), merge_depth
682
@deprecated_function(deprecated_in((2, 2, 0)))
670
683
def calculate_view_revisions(branch, start_revision, end_revision, direction,
671
684
specific_fileid, generate_merge_revisions):
672
685
"""Calculate the revisions to view.
1171
@deprecated_function(deprecated_in((2, 2, 0)))
1162
1172
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
1163
1173
include_merges=True):
1164
1174
"""Produce an iterator of revisions to show
1165
1175
:return: an iterator of (revision_id, revno, merge_depth)
1166
1176
(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
1178
if not include_merges:
1172
1179
revision_ids = mainline_revs[1:]
1173
1180
if direction == 'reverse':
1291
1298
preferred_levels = 0
1293
1300
def __init__(self, to_file, show_ids=False, show_timezone='original',
1294
delta_format=None, levels=None, show_advice=False):
1301
delta_format=None, levels=None, show_advice=False,
1302
to_exact_file=None):
1295
1303
"""Create a LogFormatter.
1297
1305
:param to_file: the file to output to
1306
:param to_exact_file: if set, gives an output stream to which
1307
non-Unicode diffs are written.
1298
1308
:param show_ids: if True, revision-ids are to be displayed
1299
1309
:param show_timezone: the timezone to use
1300
1310
:param delta_format: the level of delta information to display
1370
def show_foreign_info(self, rev, indent):
1386
def show_properties(self, revision, indent):
1387
"""Displays the custom properties returned by each registered handler.
1389
If a registered handler raises an error it is propagated.
1391
for line in self.custom_properties(revision):
1392
self.to_file.write("%s%s\n" % (indent, line))
1394
def custom_properties(self, revision):
1395
"""Format the custom properties returned by each registered handler.
1397
If a registered handler raises an error it is propagated.
1399
:return: a list of formatted lines (excluding trailing newlines)
1401
lines = self._foreign_info_properties(revision)
1402
for key, handler in properties_handler_registry.iteritems():
1403
lines.extend(self._format_properties(handler(revision)))
1406
def _foreign_info_properties(self, rev):
1371
1407
"""Custom log displayer for foreign revision identifiers.
1373
1409
:param rev: Revision object.
1375
1411
# Revision comes directly from a foreign repository
1376
1412
if isinstance(rev, foreign.ForeignRevision):
1377
self._write_properties(indent, rev.mapping.vcs.show_foreign_revid(
1413
return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
1381
1415
# Imported foreign revision revision ids always contain :
1382
1416
if not ":" in rev.revision_id:
1385
1419
# Revision was once imported from a foreign repository
1387
1421
foreign_revid, mapping = \
1388
1422
foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
1389
1423
except errors.InvalidRevisionId:
1392
self._write_properties(indent,
1426
return self._format_properties(
1393
1427
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):
1429
def _format_properties(self, properties):
1404
1431
for key, value in properties.items():
1405
self.to_file.write(indent + key + ': ' + value + '\n')
1432
lines.append(key + ': ' + value)
1407
1435
def show_diff(self, to_file, diff, indent):
1408
1436
for l in diff.rstrip().split('\n'):
1409
1437
to_file.write(indent + '%s\n' % (l,))
1440
# Separator between revisions in long format
1441
_LONG_SEP = '-' * 60
1412
1444
class LongLogFormatter(LogFormatter):
1414
1446
supports_merge_revisions = True
1417
1449
supports_tags = True
1418
1450
supports_diff = True
1452
def __init__(self, *args, **kwargs):
1453
super(LongLogFormatter, self).__init__(*args, **kwargs)
1454
if self.show_timezone == 'original':
1455
self.date_string = self._date_string_original_timezone
1457
self.date_string = self._date_string_with_timezone
1459
def _date_string_with_timezone(self, rev):
1460
return format_date(rev.timestamp, rev.timezone or 0,
1463
def _date_string_original_timezone(self, rev):
1464
return format_date_with_offset_in_original_timezone(rev.timestamp,
1420
1467
def log_revision(self, revision):
1421
1468
"""Log a revision, either merged or not."""
1422
1469
indent = ' ' * revision.merge_depth
1423
to_file = self.to_file
1424
to_file.write(indent + '-' * 60 + '\n')
1425
1471
if revision.revno is not None:
1426
to_file.write(indent + 'revno: %s%s\n' % (revision.revno,
1472
lines.append('revno: %s%s' % (revision.revno,
1427
1473
self.merge_marker(revision)))
1428
1474
if revision.tags:
1429
to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
1475
lines.append('tags: %s' % (', '.join(revision.tags)))
1430
1476
if self.show_ids:
1431
to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
1477
lines.append('revision-id: %s' % (revision.rev.revision_id,))
1433
1478
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)
1479
lines.append('parent: %s' % (parent_id,))
1480
lines.extend(self.custom_properties(revision.rev))
1438
1482
committer = revision.rev.committer
1439
1483
authors = revision.rev.get_apparent_authors()
1440
1484
if authors != [committer]:
1441
to_file.write(indent + 'author: %s\n' % (", ".join(authors),))
1442
to_file.write(indent + 'committer: %s\n' % (committer,))
1485
lines.append('author: %s' % (", ".join(authors),))
1486
lines.append('committer: %s' % (committer,))
1444
1488
branch_nick = revision.rev.properties.get('branch-nick', None)
1445
1489
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')
1490
lines.append('branch nick: %s' % (branch_nick,))
1492
lines.append('timestamp: %s' % (self.date_string(revision.rev),))
1494
lines.append('message:')
1454
1495
if not revision.rev.message:
1455
to_file.write(indent + ' (no message)\n')
1496
lines.append(' (no message)')
1457
1498
message = revision.rev.message.rstrip('\r\n')
1458
1499
for l in message.split('\n'):
1459
to_file.write(indent + ' %s\n' % (l,))
1500
lines.append(' %s' % (l,))
1502
# Dump the output, appending the delta and diff if requested
1503
to_file = self.to_file
1504
to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1460
1505
if revision.delta is not None:
1461
1506
# We don't respect delta_format for compatibility
1462
1507
revision.delta.show(to_file, self.show_ids, indent=indent,
1463
1508
short_status=False)
1464
1509
if revision.diff is not None:
1465
1510
to_file.write(indent + 'diff:\n')
1466
1512
# Note: we explicitly don't indent the diff (relative to the
1467
1513
# revision information) so that the output can be fed to patch -p0
1468
1514
self.show_diff(self.to_exact_file, revision.diff, indent)
1515
self.to_exact_file.flush()
1470
1517
def get_advice_separator(self):
1471
1518
"""Get the text separating the log from the closing advice."""
1544
1590
def __init__(self, *args, **kwargs):
1545
1591
super(LineLogFormatter, self).__init__(*args, **kwargs)
1546
self._max_chars = terminal_width() - 1
1592
width = terminal_width()
1593
if width is not None:
1594
# we need one extra space for terminals that wrap on last char
1596
self._max_chars = width
1548
1598
def truncate(self, str, max_len):
1549
if len(str) <= max_len:
1599
if max_len is None or len(str) <= max_len:
1551
return str[:max_len-3]+'...'
1601
return str[:max_len-3] + '...'
1553
1603
def date_string(self, rev):
1554
1604
return format_date(rev.timestamp, rev.timezone or 0,
1846
1896
:return: (branch, info_list, start_rev_info, end_rev_info) where
1847
1897
info_list is a list of (relative_path, file_id, kind) tuples where
1848
1898
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1899
branch will be read-locked.
1850
1901
from builtins import _get_revision_range, safe_relpath_files
1851
1902
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
1852
1904
# XXX: It's damn messy converting a list of paths to relative paths when
1853
1905
# those paths might be deleted ones, they might be on a case-insensitive
1854
1906
# filesystem and/or they might be in silly locations (like another branch).
1934
1986
properties_handler_registry = registry.Registry()
1988
# Use the properties handlers to print out bug information if available
1989
def _bugs_properties_handler(revision):
1990
if revision.properties.has_key('bugs'):
1991
bug_lines = revision.properties['bugs'].split('\n')
1992
bug_rows = [line.split(' ', 1) for line in bug_lines]
1993
fixed_bug_urls = [row[0] for row in bug_rows if
1994
len(row) > 1 and row[1] == 'fixed']
1997
return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
2000
properties_handler_registry.register('bugs_properties_handler',
2001
_bugs_properties_handler)
1937
2004
# adapters which revision ids to log are filtered. When log is called, the
1938
2005
# log_rev_iterator is adapted through each of these factory methods.