[Pkg-bazaar-commits] ./bzr/unstable r378: - New usage bzr log FILENAME

Martin Pool mbp at sourcefrog.net
Fri Apr 10 07:52:06 UTC 2009


------------------------------------------------------------
revno: 378
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Thu 2005-05-05 18:26:20 +1000
message:
  - New usage bzr log FILENAME
modified:
  NEWS
  bzrlib/commands.py
  bzrlib/log.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-05-05 07:43:42 +0000
+++ b/NEWS	2005-05-05 08:26:20 +0000
@@ -17,6 +17,9 @@
 
     * New option ``bzr log --show-ids``.
 
+    * New usage ``bzr log FILENAME`` shows only revisions that
+      affected that file.
+
   TESTING:
 
     * Converted black-box test suites from Bourne shell into Python;

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-05-05 07:43:42 +0000
+++ b/bzrlib/commands.py	2005-05-05 08:26:20 +0000
@@ -419,14 +419,14 @@
     TODO: Option to limit range.
 
     TODO: Perhaps show most-recent first with an option for last.
-
-    TODO: Option to limit to only a single file or to get log for a
-          different directory.
     """
+    takes_args = ['filename?']
     takes_options = ['timezone', 'verbose', 'show-ids']
-    def run(self, timezone='original', verbose=False, show_ids=False):
-        b = Branch('.', lock_mode='r')
-        bzrlib.show_log(b,
+    def run(self, filename=None, timezone='original', verbose=False, show_ids=False):
+        b = Branch((filename or '.'), lock_mode='r')
+        if filename:
+            filename = b.relpath(filename)
+        bzrlib.show_log(b, filename,
                         show_timezone=timezone,
                         verbose=verbose,
                         show_ids=show_ids)

=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2005-05-05 07:43:42 +0000
+++ b/bzrlib/log.py	2005-05-05 08:26:20 +0000
@@ -29,6 +29,9 @@
 
     TODO: Perhaps some way to limit this to only particular revisions,
     or to traverse a non-branch set of revisions?
+
+    TODO: If a directory is given, then by default look for all
+    changes under that directory.
     """
     last_ie = None
     last_path = None
@@ -63,11 +66,18 @@
         revno += 1
 
 
-def show_log(branch, show_timezone='original', verbose=False,
+def show_log(branch,
+             filename=None,
+             show_timezone='original',
+             verbose=False,
              show_ids=False,
              to_file=None):
     """Write out human-readable log of commits to this branch.
 
+    filename
+        If true, list only the commits affecting the specified
+        file, rather than all commits.
+
     show_timezone
         'original' (committer's timezone),
         'utc' (universal time), or
@@ -90,11 +100,20 @@
     if to_file == None:
         import sys
         to_file = sys.stdout
+
+    if filename:
+        file_id = branch.read_working_inventory().path2id(filename)
+        def which_revs():
+            for revno, revid, why in find_touching_revisions(branch, file_id):
+                yield revno, revid
+    else:
+        def which_revs():
+            for i, revid in enumerate(branch.revision_history()):
+                yield i+1, revid
         
     branch._need_readlock()
-    revno = 1
     precursor = None
-    for revision_id in branch.revision_history():
+    for revno, revision_id in which_revs():
         print >>to_file,  '-' * 60
         print >>to_file,  'revno:', revno
         rev = branch.get_revision(revision_id)
@@ -108,10 +127,6 @@
             raise BzrCheckError("retrieved wrong revision: %r"
                                 % (revision_id, rev.revision_id))
 
-        ## opportunistic consistency check, same as check_patch_chaining
-        if rev.precursor != precursor:
-            raise BzrCheckError("mismatched precursor!")
-
         print >>to_file,  'message:'
         if not rev.message:
             print >>to_file,  '  (no message)'
@@ -119,7 +134,10 @@
             for l in rev.message.split('\n'):
                 print >>to_file,  '  ' + l
 
-        if verbose and precursor:
+        # Don't show a list of changed files if we were asked about
+        # one specific file.
+
+        if verbose and precursor and not filename:
             # TODO: Group as added/deleted/renamed instead
             # TODO: Show file ids
             print >>to_file, 'changed files:'
@@ -136,5 +154,5 @@
                     show_status(file_state, kind,
                         old_name + ' => ' + new_name)
 
-        revno += 1
         precursor = revision_id
+



More information about the Pkg-bazaar-commits mailing list