~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-02-07 14:12:18 UTC
  • mfrom: (2221.4.13 registryoption)
  • Revision ID: pqm@pqm.ubuntu.com-20070207141218-c474ad3d5cf88311
Turn log format into registry option, clean up registry options

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
from itertools import izip
55
55
import re
56
56
 
57
 
from bzrlib import symbol_versioning
 
57
from bzrlib import(
 
58
    registry,
 
59
    symbol_versioning,
 
60
    )
58
61
import bzrlib.errors as errors
59
62
from bzrlib.symbol_versioning import deprecated_method, zero_eleven
60
63
from bzrlib.trace import mutter
459
462
    lf = LineLogFormatter(None)
460
463
    return lf.log_string(None, rev, max_chars)
461
464
 
462
 
FORMATTERS = {
463
 
              'long': LongLogFormatter,
464
 
              'short': ShortLogFormatter,
465
 
              'line': LineLogFormatter,
466
 
              }
 
465
 
 
466
class LogFormatterRegistry(registry.Registry):
 
467
    """Registry for log formatters"""
 
468
 
 
469
    def make_formatter(self, name, *args, **kwargs):
 
470
        """Construct a formatter from arguments.
 
471
 
 
472
        :param name: Name of the formatter to construct.  'short', 'long' and
 
473
            'line' are built-in.
 
474
        """
 
475
        return self.get(name)(*args, **kwargs)
 
476
 
 
477
    def get_default(self, branch):
 
478
        return self.get(branch.get_config().log_format())
 
479
 
 
480
 
 
481
log_formatter_registry = LogFormatterRegistry()
 
482
 
 
483
 
 
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')
 
490
 
467
491
 
468
492
def register_formatter(name, formatter):
469
 
    FORMATTERS[name] = formatter
 
493
    log_formatter_registry.register(name, formatter)
 
494
 
470
495
 
471
496
def log_formatter(name, *args, **kwargs):
472
497
    """Construct a formatter from arguments.
476
501
    """
477
502
    from bzrlib.errors import BzrCommandError
478
503
    try:
479
 
        return FORMATTERS[name](*args, **kwargs)
 
504
        return log_formatter_registry.make_formatter(name, *args, **kwargs)
480
505
    except KeyError:
481
506
        raise BzrCommandError("unknown log formatter: %r" % name)
482
507
 
 
508
 
483
509
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
484
510
    # deprecated; for compatibility
485
511
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)