54
54
from itertools import izip
61
57
import bzrlib.errors as errors
62
from bzrlib.symbol_versioning import deprecated_method, zero_eleven
63
58
from bzrlib.trace import mutter
64
59
from bzrlib.tsort import merge_sort
207
202
mainline_revs.insert(0, None)
209
204
mainline_revs.insert(0, which_revs[start_revision-2][1])
210
# how should we show merged revisions ?
211
# old api: show_merge. New api: show_merge_revno
212
show_merge_revno = getattr(lf, 'show_merge_revno', None)
213
show_merge = getattr(lf, 'show_merge', None)
214
if show_merge is None and show_merge_revno is None:
215
# no merged-revno support
216
include_merges = False
205
if getattr(lf, 'show_merge', None) is not None:
206
include_merges = True
218
include_merges = True
219
if show_merge is not None and show_merge_revno is None:
220
# tell developers to update their code
221
symbol_versioning.warn('LogFormatters should provide show_merge_revno '
222
'instead of show_merge since bzr 0.11.',
223
DeprecationWarning, stacklevel=3)
208
include_merges = False
224
209
view_revisions = list(get_view_revisions(mainline_revs, rev_nos, branch,
225
210
direction, include_merges=include_merges))
269
254
lf.show(revno, rev, delta)
271
if show_merge_revno is None:
272
lf.show_merge(rev, merge_depth)
274
lf.show_merge_revno(rev, merge_depth, revno)
256
lf.show_merge(rev, merge_depth)
277
259
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
285
267
if direction == 'reverse':
286
268
revision_ids.reverse()
287
269
for revision_id in revision_ids:
288
yield revision_id, str(rev_nos[revision_id]), 0
270
yield revision_id, rev_nos[revision_id], 0
290
272
merge_sorted_revisions = merge_sort(
291
273
branch.repository.get_revision_graph(mainline_revs[-1]),
292
274
mainline_revs[-1],
296
277
if direction == 'forward':
297
278
# forward means oldest first.
299
280
elif direction != 'reverse':
300
281
raise ValueError('invalid direction %r' % direction)
302
for sequence, rev_id, merge_depth, revno, end_of_merge in merge_sorted_revisions:
303
yield rev_id, '.'.join(map(str, revno)), merge_depth
283
revision_history = branch.revision_history()
285
for sequence, rev_id, merge_depth, end_of_merge in merge_sorted_revisions:
286
yield rev_id, rev_nos.get(rev_id), merge_depth
306
289
def reverse_by_depth(merge_sorted_revisions, _depth=0):
346
329
def show(self, revno, rev, delta):
347
330
return self._show_helper(revno=revno, rev=rev, delta=delta)
349
@deprecated_method(zero_eleven)
350
332
def show_merge(self, rev, merge_depth):
351
333
return self._show_helper(rev=rev, indent=' '*merge_depth, merged=True, delta=None)
353
def show_merge_revno(self, rev, merge_depth, revno):
354
"""Show a merged revision rev, with merge_depth and a revno."""
355
return self._show_helper(rev=rev, revno=revno,
356
indent=' '*merge_depth, merged=True, delta=None)
358
335
def _show_helper(self, rev=None, revno=None, indent='', merged=False, delta=None):
359
336
"""Show a revision, either merged or not."""
360
337
from bzrlib.osutils import format_date
361
338
to_file = self.to_file
362
339
print >>to_file, indent+'-' * 60
363
340
if revno is not None:
364
print >>to_file, indent+'revno:', revno
341
print >>to_file, 'revno:', revno
366
343
print >>to_file, indent+'merged:', rev.revision_id
367
344
elif self.show_ids:
398
375
to_file = self.to_file
399
376
date_str = format_date(rev.timestamp, rev.timezone or 0,
400
377
self.show_timezone)
401
print >>to_file, "%5s %s\t%s" % (revno, self.short_committer(rev),
378
print >>to_file, "%5d %s\t%s" % (revno, self.short_committer(rev),
402
379
format_date(rev.timestamp, rev.timezone or 0,
403
380
self.show_timezone, date_fmt="%Y-%m-%d",
404
381
show_offset=False))
453
430
# show revno only when is not None
454
out.append("%s:" % revno)
431
out.append("%d:" % revno)
455
432
out.append(self.truncate(self.short_committer(rev), 20))
456
433
out.append(self.date_string(rev))
457
434
out.append(rev.get_summary())
462
439
lf = LineLogFormatter(None)
463
440
return lf.log_string(None, rev, max_chars)
466
class LogFormatterRegistry(registry.Registry):
467
"""Registry for log formatters"""
469
def make_formatter(self, name, *args, **kwargs):
470
"""Construct a formatter from arguments.
472
:param name: Name of the formatter to construct. 'short', 'long' and
475
return self.get(name)(*args, **kwargs)
477
def get_default(self, branch):
478
return self.get(branch.get_config().log_format())
481
log_formatter_registry = LogFormatterRegistry()
484
log_formatter_registry.register('short', ShortLogFormatter,
485
'Moderately short log format')
486
log_formatter_registry.register('long', LongLogFormatter,
487
'Detailed log format')
488
log_formatter_registry.register('line', LineLogFormatter,
489
'Log format with one line per revision')
443
'long': LongLogFormatter,
444
'short': ShortLogFormatter,
445
'line': LineLogFormatter,
492
448
def register_formatter(name, formatter):
493
log_formatter_registry.register(name, formatter)
449
FORMATTERS[name] = formatter
496
451
def log_formatter(name, *args, **kwargs):
497
452
"""Construct a formatter from arguments.
502
457
from bzrlib.errors import BzrCommandError
504
return log_formatter_registry.make_formatter(name, *args, **kwargs)
459
return FORMATTERS[name](*args, **kwargs)
506
461
raise BzrCommandError("unknown log formatter: %r" % name)
509
463
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
510
464
# deprecated; for compatibility
511
465
lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)