Rev 2389: [merge] James Westby's work on refactoring LogFormatter. in http://bzr.arbash-meinel.com/branches/bzr/0.16-dev/log_fixes

John Arbash Meinel john at arbash-meinel.com
Mon Apr 2 17:24:01 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.16-dev/log_fixes

------------------------------------------------------------
revno: 2389
revision-id: john at arbash-meinel.com-20070402162342-cq1k9ihfl52eljwy
parent: pqm at pqm.ubuntu.com-20070330064022-bdce9356befc3795
parent: jw+debian at jameswestby.net-20070201214800-3u3ad6h0p7nwbcx6
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: log_fixes
timestamp: Mon 2007-04-02 11:23:42 -0500
message:
  [merge] James Westby's work on refactoring LogFormatter.
modified:
  bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
  bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
    ------------------------------------------------------------
    revno: 2245.9.1
    merged: jw+debian at jameswestby.net-20070201214800-3u3ad6h0p7nwbcx6
    parent: pqm at pqm.ubuntu.com-20070125194626-4ded330415b7276d
    committer: James Westby <jw+debian at jameswestby.net>
    branch nick: bzr.dev.logformat3
    timestamp: Thu 2007-02-01 21:48:00 +0000
    message:
      Add a show_log method to LogFormatter, allowing them to be more complex.
      
      When a LogFormatter has the show_log method they have more access to the
      information about what is being shown, allowing them to do more complex
      things. This change adds the method to them, but still allows for
      non-LogFormatters to be used, and just deprecates them not providing the
      new method.
      
      Those wanting to display a log should still call show_log(branch, lf...
      as before, but this will change to lf.show_log(branch... after the
      deprecation period.
-------------- next part --------------
=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2007-02-07 03:09:58 +0000
+++ b/bzrlib/log.py	2007-04-02 16:23:42 +0000
@@ -148,6 +148,19 @@
     end_revision
         If not None, only show revisions <= end_revision
     """
+    log_func = getattr(lf, 'show_log', None)
+    if log_func is not None:
+        return lf.show_log(branch,
+                           specific_fileid=specific_fileid,
+                           verbose=verbose,
+                           direction=direction,
+                           start_revision=start_revision,
+                           end_revision=end_revision,
+                           search=search)
+
+    symbol_versioning.warn('Log formatters should provide a show_log '
+                           'function as of version 0.15',
+                           DeprecationWarning)
     branch.lock_read()
     try:
         _show_log(branch, lf, specific_fileid, verbose, direction,
@@ -167,11 +180,6 @@
     from bzrlib.osutils import format_date
     from bzrlib.errors import BzrCheckError
     
-    from warnings import warn
-
-    if not isinstance(lf, LogFormatter):
-        warn("not a LogFormatter instance: %r" % lf)
-
     if specific_fileid:
         mutter('get log for file_id %r', specific_fileid)
 
@@ -341,6 +349,46 @@
     def short_committer(self, rev):
         return re.sub('<.*@.*>', '', rev.committer).strip(' ')
     
+    def show_log(self,
+                 branch,
+                 specific_fileid=None,
+                 verbose=False,
+                 direction='reverse',
+                 start_revision=None,
+                 end_revision=None,
+                 search=None):
+        """Write out human-readable log of commits to a branch.
+
+        branch
+            The branch to take the commits from.
+
+        specific_fileid
+            If true, list only the commits affecting the specified
+            file, rather than all commits.
+
+        verbose
+            If true show added/changed/deleted/renamed files.
+
+        direction
+            'reverse' (default) is latest to earliest;
+            'forward' is earliest to latest.
+
+        start_revision
+            If not None, only show revisions >= start_revision
+
+        end_revision
+            If not None, only show revisions <= end_revision
+
+        search
+            A string containing a regular expression to only show
+            commits that match that expression
+        """
+        branch.lock_read()
+        try:
+            _show_log(branch, self, specific_fileid, verbose, direction,
+                      start_revision, end_revision, search)
+        finally:
+            branch.unlock()
     
 class LongLogFormatter(LogFormatter):
     def show(self, revno, rev, delta):

=== modified file 'bzrlib/tests/test_log.py'
--- a/bzrlib/tests/test_log.py	2006-11-03 18:35:29 +0000
+++ b/bzrlib/tests/test_log.py	2007-02-01 21:48:00 +0000
@@ -28,6 +28,7 @@
                         LineLogFormatter)
 from bzrlib.branch import Branch
 from bzrlib.errors import InvalidRevisionNumber
+from bzrlib.symbol_versioning import zero_fifteen
 
 
 class _LogEntry(object):
@@ -400,3 +401,92 @@
         self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
             ('4b', '4', 0)],
             revisions)
+
+    def test_lack_of_show_log_deprecated(self):
+      """Tests that LogFormatters must have show_log().
+
+      This test checks that show_log(lf, ... throws is deprecated if
+      lf doesn't have a show_log() method.
+
+      It also checks that the output is correct in this case.
+      """
+
+      class LogFormatterNoShowLog(object):
+
+        def __init__(self):
+          self.revnos = []
+
+        def show(self, revno, rev, delta):
+          self.revnos.append(revno)
+
+      log_formatter = LogFormatterNoShowLog()
+
+      wt = self.make_branch_and_tree('tree1')
+      wt.commit('commit one', rev_id='1', timestamp=1123123123.000,
+                timezone=36000,
+                committer='Line-Log-Formatter Tester <test at line.log>')
+      self.callDeprecated(['Log formatters should provide a show_log '
+                           'function as of version 0.15'], show_log,
+                           wt.branch, log_formatter)
+      self.assertEqual(log_formatter.revnos, ['1'])
+
+    def test_show_log_method_called(self):
+      """Test that the LogFormatter's show_log method is called.
+
+      Check that a call to show_log(lf... then calls lf.show_log()
+      """
+
+      class LogFormatterShowLog(LogFormatter):
+
+        def __init__(self, *args, **kwargs):
+          super(LogFormatterShowLog, self).__init__(*args, **kwargs)
+          self.branch = None
+          self.specific_fileid = None
+          self.verbose = False
+          self.direction = 'reverse'
+          self.start_revision = None
+          self.end_revision = None
+          self.search = None
+
+        def show_log(self,
+                     branch,
+                     specific_fileid=None,
+                     verbose=False,
+                     direction='reverse',
+                     start_revision=None,
+                     end_revision=None,
+                     search=None):
+
+          self.branch = branch
+          self.specific_fileid = specific_fileid
+          self.verbose = verbose
+          self.direction = direction
+          self.start_revision = start_revision
+          self.end_revision = end_revision
+          self.search = search
+
+      log_formatter = LogFormatterShowLog('logfile')
+
+      wt = self.make_branch_and_tree('tree1')
+      wt.commit('commit one', rev_id='1')
+      wt.commit('commit two', rev_id='2')
+
+      specific_fileid = 'a'
+      verbose = True
+      direction = 'forward'
+      start_revision = 1
+      end_revision = 2
+      search = 'a'
+
+      show_log(wt.branch, log_formatter, specific_fileid,
+               verbose, direction, start_revision,
+               end_revision, search)
+
+      self.assertEqual(wt.branch, log_formatter.branch)
+      self.assertEqual(specific_fileid, log_formatter.specific_fileid)
+      self.assertEqual(verbose, log_formatter.verbose)
+      self.assertEqual(direction, log_formatter.direction)
+      self.assertEqual(start_revision, log_formatter.start_revision)
+      self.assertEqual(end_revision, log_formatter.end_revision)
+      self.assertEqual(search, log_formatter.search)
+



More information about the bazaar-commits mailing list