[Pkg-bazaar-commits] ./bzr/unstable r369: - Split out log printing into new show_log function

Martin Pool mbp at sourcefrog.net
Fri Apr 10 07:43:42 UTC 2009


------------------------------------------------------------
revno: 369
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Thu 2005-05-05 16:59:12 +1000
message:
  - Split out log printing into new show_log function
    not as a method of Branch.
added:
  bzrlib/log.py
modified:
  bzrlib/__init__.py
  bzrlib/branch.py
  bzrlib/commands.py
  bzrlib/tests.py
-------------- next part --------------
=== modified file 'bzrlib/__init__.py'
--- a/bzrlib/__init__.py	2005-05-05 06:38:18 +0000
+++ b/bzrlib/__init__.py	2005-05-05 06:59:12 +0000
@@ -22,6 +22,7 @@
 from tree import Tree
 from diff import diff_trees
 from trace import mutter, warning, open_tracefile
+from log import show_log
 import add
 
 BZRDIR = ".bzr"

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2005-05-05 06:51:45 +0000
+++ b/bzrlib/branch.py	2005-05-05 06:59:12 +0000
@@ -773,67 +773,6 @@
 
 
 
-    def write_log(self, show_timezone='original', verbose=False,
-                  show_ids=False):
-        """Write out human-readable log of commits to this branch.
-
-        show_timezone
-            'original' (committer's timezone),
-            'utc' (universal time), or
-            'local' (local user's timezone)
-
-        verbose
-            If true show added/changed/deleted/renamed files.
-
-        show_ids
-            If true, show revision and file ids.
-        """
-        
-        self._need_readlock()
-        revno = 1
-        precursor = None
-        for p in self.revision_history():
-            print '-' * 40
-            print 'revno:', revno
-            rev = self.get_revision(p)
-            if show_ids:
-                print 'revision-id:', rev.revision_id
-            print 'committer:', rev.committer
-            print 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0,
-                                                 show_timezone))
-
-            ## opportunistic consistency check, same as check_patch_chaining
-            if rev.precursor != precursor:
-                raise BzrCheckError("mismatched precursor!")
-
-            print 'message:'
-            if not rev.message:
-                print '  (no message)'
-            else:
-                for l in rev.message.split('\n'):
-                    print '  ' + l
-
-            if verbose == True and precursor != None:
-                # TODO: Group as added/deleted/renamed instead
-                # TODO: Show file ids
-                print 'changed files:'
-                tree = self.revision_tree(p)
-                prevtree = self.revision_tree(precursor)
-                
-                for file_state, fid, old_name, new_name, kind in \
-                                        diff_trees(prevtree, tree, ):
-                    if file_state == 'A' or file_state == 'M':
-                        show_status(file_state, kind, new_name)
-                    elif file_state == 'D':
-                        show_status(file_state, kind, old_name)
-                    elif file_state == 'R':
-                        show_status(file_state, kind,
-                            old_name + ' => ' + new_name)
-                
-            revno += 1
-            precursor = p
-
-
     def rename_one(self, from_rel, to_rel):
         """Rename one file.
 

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-05-05 06:51:01 +0000
+++ b/bzrlib/commands.py	2005-05-05 06:59:12 +0000
@@ -426,9 +426,9 @@
     takes_options = ['timezone', 'verbose', 'show-ids']
     def run(self, timezone='original', verbose=False, show_ids=False):
         b = Branch('.', lock_mode='r')
-        b.write_log(show_timezone=timezone,
-                    verbose=verbose,
-                    show_ids=show_ids)
+        b.show_log(show_timezone=timezone,
+                   verbose=verbose,
+                   show_ids=show_ids)
 
 
 class cmd_ls(Command):

=== added file 'bzrlib/log.py'
--- a/bzrlib/log.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/log.py	2005-05-05 06:59:12 +0000
@@ -0,0 +1,87 @@
+# Copyright (C) 2005 Canonical Ltd
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+def show_log(branch, show_timezone='original', verbose=False,
+             show_ids=False,
+             to_file=None):
+    """Write out human-readable log of commits to this branch.
+
+    show_timezone
+        'original' (committer's timezone),
+        'utc' (universal time), or
+        'local' (local user's timezone)
+
+    verbose
+        If true show added/changed/deleted/renamed files.
+
+    show_ids
+        If true, show revision and file ids.
+
+    to_file
+        File to send log to; by default stdout.
+    """
+    from osutils import format_date
+    from errors import BzrCheckError
+    from diff import diff_trees
+    from textui import show_status
+
+    if to_file == None:
+        import sys
+        to_file = sys.stdout
+        
+    branch._need_readlock()
+    revno = 1
+    precursor = None
+    for revision_id in branch.revision_history():
+        print '-' * 40
+        print 'revno:', revno
+        rev = branch.get_revision(revision_id)
+        if show_ids:
+            print 'revision-id:', revision_id
+        print 'committer:', rev.committer
+        print 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0,
+                                             show_timezone))
+
+        ## opportunistic consistency check, same as check_patch_chaining
+        if rev.precursor != precursor:
+            raise BzrCheckError("mismatched precursor!")
+
+        print 'message:'
+        if not rev.message:
+            print '  (no message)'
+        else:
+            for l in rev.message.split('\n'):
+                print '  ' + l
+
+        if verbose and precursor:
+            # TODO: Group as added/deleted/renamed instead
+            # TODO: Show file ids
+            print 'changed files:'
+            tree = branch.revision_tree(revision_id)
+            prevtree = branch.revision_tree(precursor)
+
+            for file_state, fid, old_name, new_name, kind in \
+                                    diff_trees(prevtree, tree, ):
+                if file_state == 'A' or file_state == 'M':
+                    show_status(file_state, kind, new_name)
+                elif file_state == 'D':
+                    show_status(file_state, kind, old_name)
+                elif file_state == 'R':
+                    show_status(file_state, kind,
+                        old_name + ' => ' + new_name)
+
+        revno += 1
+        precursor = revision_id

=== modified file 'bzrlib/tests.py'
--- a/bzrlib/tests.py	2005-05-03 12:37:47 +0000
+++ b/bzrlib/tests.py	2005-05-05 06:59:12 +0000
@@ -101,7 +101,7 @@
   >>> r = b.get_revision(b.lookup_revision(1))
   >>> r.message
   'start hello world'
-  >>> b.write_log(show_timezone='utc')
+  >>> bzrlib.show_log(b, show_timezone='utc')
   ----------------------------------------
   revno: 1
   committer: foo at nowhere



More information about the Pkg-bazaar-commits mailing list