[merge] accept LogFormatter instances in cmd_log.run

Adeodato Simó dato at net.com.org.es
Fri Jul 28 13:40:43 BST 2006


For me, one of the things that makes me most happy about bzr, is the
fact that it gives me enough rope to hang myself [1]. In other words,
that thanks to plugins users are allowed to customize it heavily if they
so wish, in ways that may be no appropriate for bzr mainline.

Since I do this regularly, I always have a handful of ideas to make the
API more useful to third-party code. I let them mature, let the ones
that are crackful die, and propose the sensible ones here :-P, e.g.

Another one that strikes me as sensible is having cmd_log.run accept a
LogFormatter instance in the log_format argument. The rationale is the
following: one can, of course, create a CustomLogFormatter class,
register it, and call log with log_format='custom_format'. However, this
is of little use when one wants the class to collect data, since there
is no way to retrieve the created CustomLogFormatter instance back from

Hence the attached patch [2]. I also think something similar should be
done for for all "options accepts these values, plugins can register
more" options (e.g. --template in my commit_templates branch).

About the patch, I've tried to figure where this could be tested, but I
didn't found any test for a similar functionality, so any suggestions
are welcome.



  [1] http://chistera.yi.org/~adeodato/blog/bzr/54_wrapping_bzr_diff.html
  [2] http://people.debian.org/~adeodato/code/bzr/branches/log_accept_log_formatter

Adeodato Simó                                     dato at net.com.org.es
Debian Developer                                  adeodato at debian.org
You've come to the right place.  At debian-devel we are always willing
to argue over the meanings of words.
                -- seen on debian-devel at l.d.o
-------------- next part --------------
# Bazaar revision bundle v0.8
# message:
#   bzrlib/builtins.py:
#     - (cmd_log.run) accept log_format to be a LogFormatter instance.
# committer: Adeodato Simó <dato at net.com.org.es>
# date: Fri 2006-07-28 14:09:58.588000059 +0200

=== modified file bzrlib/builtins.py
--- bzrlib/builtins.py
+++ bzrlib/builtins.py
@@ -1315,7 +1315,7 @@
-        from bzrlib.log import log_formatter, show_log
+        from bzrlib.log import log_formatter, show_log, LogFormatter
         assert message is None or isinstance(message, basestring), \
             "invalid message argument %r" % message
         direction = (forward and 'forward') or 'reverse'
@@ -1371,10 +1371,14 @@
             default = b.get_config().log_format()
             log_format = get_log_format(long=long, short=short, line=line, 
-        lf = log_formatter(log_format,
-                           show_ids=show_ids,
-                           to_file=self.outf,
-                           show_timezone=timezone)
+        if not isinstance(log_format, LogFormatter):
+            lf = log_formatter(log_format,
+                            show_ids=show_ids,
+                            to_file=self.outf,
+                            show_timezone=timezone)
+        else:
+            lf = log_format

# revision id: dato at net.com.org.es-20060728120958-6887cdc39925a655
# sha1: f8453f248a6ef0a35d48b4e1617c1cb20128d3a6
# inventory sha1: febb914d1a8180ca40e923a3f5e6c095bd09fb95
# parent ids:
#   pqm at pqm.ubuntu.com-20060727200511-3bfb6377b1695fad
# base id: pqm at pqm.ubuntu.com-20060727200511-3bfb6377b1695fad
# properties:
#   branch-nick: log_accept_log_formatter

More information about the bazaar mailing list