389
383
:return: An iterator yielding LogRevision objects.
392
levels = rqst.get('levels')
393
limit = rqst.get('limit')
394
diff_type = rqst.get('diff_type')
396
387
revision_iterator = self._create_log_revision_iterator()
397
388
for revs in revision_iterator:
398
389
for (rev_id, revno, merge_depth), rev, delta in revs:
399
390
# 0 levels means show everything; merge_depth counts from 0
391
levels = rqst.get('levels')
400
392
if levels != 0 and merge_depth >= levels:
402
if diff_type is None:
405
diff = self._format_diff(rev, rev_id, diff_type)
394
diff = self._format_diff(rev, rev_id)
406
395
yield LogRevision(rev, revno, merge_depth, delta,
407
396
self.rev_tag_dict.get(rev_id), diff)
397
limit = rqst.get('limit')
410
400
if log_count >= limit:
413
def _format_diff(self, rev, rev_id, diff_type):
403
def _format_diff(self, rev, rev_id):
404
diff_type = self.rqst.get('diff_type')
405
if diff_type is None:
414
407
repo = self.branch.repository
415
408
if len(rev.parent_ids) == 0:
416
409
ancestor_id = _mod_revision.NULL_REVISION
536
529
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
537
delayed_graph_generation):
530
delayed_graph_generation):
538
531
# On large trees, generating the merge graph can take 30-60 seconds
539
532
# so we delay doing it until a merge is detected, incrementally
540
533
# 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
534
initial_revisions = []
546
535
if delayed_graph_generation:
548
for rev_id, revno, depth in _linear_view_revisions(
549
branch, start_rev_id, end_rev_id):
537
for rev_id, revno, depth in \
538
_linear_view_revisions(branch, start_rev_id, end_rev_id):
550
539
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
540
end_rev_id = rev_id
684
661
depth_adjustment = merge_depth
685
662
if depth_adjustment:
686
663
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
664
depth_adjustment = merge_depth
692
665
merge_depth -= depth_adjustment
693
666
yield rev_id, '.'.join(map(str, revno)), merge_depth
696
@deprecated_function(deprecated_in((2, 2, 0)))
697
669
def calculate_view_revisions(branch, start_revision, end_revision, direction,
698
670
specific_fileid, generate_merge_revisions):
699
671
"""Calculate the revisions to view.
1185
@deprecated_function(deprecated_in((2, 2, 0)))
1186
1161
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
1187
1162
include_merges=True):
1188
1163
"""Produce an iterator of revisions to show
1189
1164
:return: an iterator of (revision_id, revno, merge_depth)
1190
1165
(if there is no revno for a revision, None is supplied)
1167
# This method is no longer called by the main code path.
1168
# It is retained for API compatibility and may be deprecated
1169
# soon. IGC 20090127
1192
1170
if not include_merges:
1193
1171
revision_ids = mainline_revs[1:]
1194
1172
if direction == 'reverse':
1312
1290
preferred_levels = 0
1314
1292
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):
1293
delta_format=None, levels=None, show_advice=False):
1317
1294
"""Create a LogFormatter.
1319
1296
: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
1297
:param show_ids: if True, revision-ids are to be displayed
1323
1298
:param show_timezone: the timezone to use
1324
1299
:param delta_format: the level of delta information to display
1403
1372
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
1374
for key, handler in properties_handler_registry.iteritems():
1417
lines.extend(self._format_properties(handler(revision)))
1420
def _foreign_info_properties(self, rev):
1421
"""Custom log displayer for foreign revision identifiers.
1423
:param rev: Revision object.
1425
# Revision comes directly from a foreign repository
1426
if isinstance(rev, foreign.ForeignRevision):
1427
return self._format_properties(rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
1429
# Imported foreign revision revision ids always contain :
1430
if not ":" in rev.revision_id:
1433
# Revision was once imported from a foreign repository
1435
foreign_revid, mapping = \
1436
foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
1437
except errors.InvalidRevisionId:
1440
return self._format_properties(
1441
mapping.vcs.show_foreign_revid(foreign_revid))
1443
def _format_properties(self, properties):
1445
for key, value in properties.items():
1446
lines.append(key + ': ' + value)
1375
for key, value in handler(revision).items():
1376
self.to_file.write(indent + key + ': ' + value + '\n')
1449
1378
def show_diff(self, to_file, diff, indent):
1450
1379
for l in diff.rstrip().split('\n'):
1451
1380
to_file.write(indent + '%s\n' % (l,))
1454
# Separator between revisions in long format
1455
_LONG_SEP = '-' * 60
1458
1383
class LongLogFormatter(LogFormatter):
1460
1385
supports_merge_revisions = True
1463
1388
supports_tags = True
1464
1389
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
1391
def log_revision(self, revision):
1482
1392
"""Log a revision, either merged or not."""
1483
1393
indent = ' ' * revision.merge_depth
1394
to_file = self.to_file
1395
to_file.write(indent + '-' * 60 + '\n')
1485
1396
if revision.revno is not None:
1486
lines.append('revno: %s%s' % (revision.revno,
1397
to_file.write(indent + 'revno: %s%s\n' % (revision.revno,
1487
1398
self.merge_marker(revision)))
1488
1399
if revision.tags:
1489
lines.append('tags: %s' % (', '.join(revision.tags)))
1400
to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
1490
1401
if self.show_ids:
1491
lines.append('revision-id: %s' % (revision.rev.revision_id,))
1402
to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
1492
1404
for parent_id in revision.rev.parent_ids:
1493
lines.append('parent: %s' % (parent_id,))
1494
lines.extend(self.custom_properties(revision.rev))
1405
to_file.write(indent + 'parent: %s\n' % (parent_id,))
1406
self.show_properties(revision.rev, indent)
1496
1408
committer = revision.rev.committer
1497
1409
authors = revision.rev.get_apparent_authors()
1498
1410
if authors != [committer]:
1499
lines.append('author: %s' % (", ".join(authors),))
1500
lines.append('committer: %s' % (committer,))
1411
to_file.write(indent + 'author: %s\n' % (", ".join(authors),))
1412
to_file.write(indent + 'committer: %s\n' % (committer,))
1502
1414
branch_nick = revision.rev.properties.get('branch-nick', None)
1503
1415
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:')
1416
to_file.write(indent + 'branch nick: %s\n' % (branch_nick,))
1418
date_str = format_date(revision.rev.timestamp,
1419
revision.rev.timezone or 0,
1421
to_file.write(indent + 'timestamp: %s\n' % (date_str,))
1423
to_file.write(indent + 'message:\n')
1509
1424
if not revision.rev.message:
1510
lines.append(' (no message)')
1425
to_file.write(indent + ' (no message)\n')
1512
1427
message = revision.rev.message.rstrip('\r\n')
1513
1428
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)))
1429
to_file.write(indent + ' %s\n' % (l,))
1519
1430
if revision.delta is not None:
1520
1431
# We don't respect delta_format for compatibility
1521
1432
revision.delta.show(to_file, self.show_ids, indent=indent,
1522
1433
short_status=False)
1523
1434
if revision.diff is not None:
1524
1435
to_file.write(indent + 'diff:\n')
1526
1436
# Note: we explicitly don't indent the diff (relative to the
1527
1437
# revision information) so that the output can be fed to patch -p0
1528
1438
self.show_diff(self.to_exact_file, revision.diff, indent)
1529
self.to_exact_file.flush()
1531
1440
def get_advice_separator(self):
1532
1441
"""Get the text separating the log from the closing advice."""
1604
1513
def __init__(self, *args, **kwargs):
1605
1514
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
1515
self._max_chars = terminal_width() - 1
1612
1517
def truncate(self, str, max_len):
1613
if max_len is None or len(str) <= max_len:
1518
if len(str) <= max_len:
1615
return str[:max_len-3] + '...'
1520
return str[:max_len-3]+'...'
1617
1522
def date_string(self, rev):
1618
1523
return format_date(rev.timestamp, rev.timezone or 0,
1910
1815
:return: (branch, info_list, start_rev_info, end_rev_info) where
1911
1816
info_list is a list of (relative_path, file_id, kind) tuples where
1912
1817
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1913
branch will be read-locked.
1915
1819
from builtins import _get_revision_range, safe_relpath_files
1916
1820
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
1918
1821
# XXX: It's damn messy converting a list of paths to relative paths when
1919
1822
# those paths might be deleted ones, they might be on a case-insensitive
1920
1823
# filesystem and/or they might be in silly locations (like another branch).
2000
1903
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)
1904
properties_handler_registry.register_lazy("foreign",
1906
"show_foreign_properties")
2018
1909
# adapters which revision ids to log are filtered. When log is called, the