343
343
class LogFormatter(object):
344
344
"""Abstract class to display log messages."""
345
346
def __init__(self, to_file, show_ids=False, show_timezone='original'):
346
347
self.to_file = to_file
347
348
self.show_ids = show_ids
348
349
self.show_timezone = show_timezone
351
351
def show(self, revno, rev, delta):
352
352
raise NotImplementedError('not implemented in abstract base')
424
424
delta.show(to_file, self.show_ids)
425
425
print >>to_file, ''
427
428
class LineLogFormatter(LogFormatter):
428
429
def truncate(self, str, max_len):
429
430
if len(str) <= max_len:
445
446
def show(self, revno, rev, delta):
446
447
from bzrlib.osutils import terminal_width
447
print >> self.to_file, self.log_string(rev, terminal_width() - 1)
448
print >> self.to_file, self.log_string(revno, rev, terminal_width()-1)
449
def log_string(self, rev, max_chars):
450
out = [self.truncate(self.short_committer(rev), 20)]
450
def log_string(self, revno, rev, max_chars):
451
"""Format log info into one string. Truncate tail of string
452
:param revno: revision number (int) or None.
453
Revision numbers counts from 1.
454
:param rev: revision info object
455
:param max_chars: maximum length of resulting string
456
:return: formatted truncated string
460
# show revno only when is not None
461
out.append("%d:" % revno)
462
out.append(self.truncate(self.short_committer(rev), 20))
451
463
out.append(self.date_string(rev))
452
464
out.append(self.message(rev).replace('\n', ' '))
453
465
return self.truncate(" ".join(out).rstrip('\n'), max_chars)
455
468
def line_log(rev, max_chars):
456
469
lf = LineLogFormatter(None)
457
return lf.log_string(rev, max_chars)
470
return lf.log_string(None, rev, max_chars)
460
473
'long': LongLogFormatter,