[PATCH] Add bzr status --short flag for svn style status

Keir Mierle keir at cs.toronto.edu
Wed Nov 22 08:47:00 GMT 2006


I've been itching for this for awhile, and since I saw I'm not alone, I cooked
up this patch. I'd like to get it upstream, so a) please try it out and b) let
me know if it is sufficient.

Essentially, it allows users to get svn style status via the --short flag to
status. See:

 $ bzr status
 added:
  foo
  bar
 removed:
  baz
 unknown:
  wooley

Compared to the --short option:

 $ bzr status --short
 A foo
 A bar
 D baz
 ? wooley

I much prefer the --short variety, because 1) my brain is used to parsing svn
status messages 2) it is possible to parse the output trivially via grep, and
3) the command output is still informative when status outputs more files than
the length of your scrollback buffer.

Keir
-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
#   Add a --short flag to status to get svn-style status
# committer: Keir Mierle <keir at cs.utoronto.ca>
# date: Wed 2006-11-22 03:36:20.407000065 -0500

=== modified file bzrlib/builtins.py
--- bzrlib/builtins.py
+++ bzrlib/builtins.py
@@ -128,26 +128,29 @@
     This reports on versioned and unknown files, reporting them
     grouped by state.  Possible states are:
 
-    added
+    added / A
         Versioned in the working copy but not in the previous revision.
 
-    removed
+    removed / D
         Versioned in the previous revision but removed or deleted
         in the working copy.
 
-    renamed
+    renamed / R
         Path of this file changed from the previous revision;
         the text may also have changed.  This includes files whose
         parent directory was renamed.
 
-    modified
+    modified / M
         Text has changed since the previous revision.
 
-    unknown
+    unknown / ?
         Not versioned and not matching an ignore pattern.
 
     To see ignored files use 'bzr ignored'.  For details in the
     changes to file texts, use 'bzr diff'.
+    
+    --short gives a one character status flag for each item, similar
+    to the SVN's status command.
 
     If no arguments are specified, the status of the entire working
     directory is shown.  Otherwise, only the status of the specified
@@ -161,20 +164,21 @@
     # TODO: --no-recurse, --recurse options
     
     takes_args = ['file*']
-    takes_options = ['show-ids', 'revision']
+    takes_options = ['show-ids', 'revision', 'short']
     aliases = ['st', 'stat']
 
     encoding_type = 'replace'
     
     @display_command
-    def run(self, show_ids=False, file_list=None, revision=None):
+    def run(self, show_ids=False, file_list=None, revision=None, short=False):
         from bzrlib.status import show_tree_status
 
         tree, file_list = tree_files(file_list)
             
         show_tree_status(tree, show_ids=show_ids,
                          specific_files=file_list, revision=revision,
-                         to_file=self.outf)
+                         to_file=self.outf,
+                         short=short)
 
 
 class cmd_cat_revision(Command):

=== modified file bzrlib/delta.py
--- bzrlib/delta.py
+++ bzrlib/delta.py
@@ -90,9 +90,9 @@
         return False
             
 
-    def show(self, to_file, show_ids=False, show_unchanged=False):
+    def show(self, to_file, show_ids=False, show_unchanged=False, short_status=False):
         """output this delta in status-like form to to_file."""
-        def show_list(files):
+        def show_list(files, short_status_letter=''):
             for item in files:
                 path, fid, kind = item[:3]
 
@@ -107,20 +107,29 @@
                 if show_ids:
                     print >>to_file, '  %-30s %s' % (path, fid)
                 else:
-                    print >>to_file, ' ', path
+                    print >>to_file, '%s %s' % (short_status_letter, path)
             
         if self.removed:
-            print >>to_file, 'removed:'
-            show_list(self.removed)
+            if not short_status:
+                print >>to_file, 'removed:'
+                show_list(self.removed)
+            else:
+                show_list(self.removed, 'D')
                 
         if self.added:
-            print >>to_file, 'added:'
-            show_list(self.added)
+            if not short_status:
+                print >>to_file, 'added:'
+                show_list(self.added)
+            else:
+                show_list(self.added, 'A')
 
         extra_modified = []
 
         if self.renamed:
-            print >>to_file, 'renamed:'
+            short_status_letter = 'R'
+            if not short_status:
+                print >>to_file, 'renamed:'
+                short_status_letter = ''
             for (oldpath, newpath, fid, kind,
                  text_modified, meta_modified) in self.renamed:
                 if text_modified or meta_modified:
@@ -129,18 +138,26 @@
                 if meta_modified:
                     newpath += '*'
                 if show_ids:
-                    print >>to_file, '  %s => %s %s' % (oldpath, newpath, fid)
+                    print >>to_file, '%s  %s => %s %s' % (short_status_letter,
+                                                          oldpath, newpath, fid)
                 else:
-                    print >>to_file, '  %s => %s' % (oldpath, newpath)
+                    print >>to_file, '%s  %s => %s' % (short_status_letter,
+                                                       oldpath, newpath)
                     
         if self.modified or extra_modified:
-            print >>to_file, 'modified:'
-            show_list(self.modified)
-            show_list(extra_modified)
+            short_status_letter = 'M'
+            if not short_status:
+                print >>to_file, 'modified:'
+                short_status_letter = ''
+            show_list(self.modified, short_status_letter)
+            show_list(extra_modified, short_status_letter)
             
         if show_unchanged and self.unchanged:
-            print >>to_file, 'unchanged:'
-            show_list(self.unchanged)
+            if not short_status:
+                print >>to_file, 'unchanged:'
+                show_list(self.unchanged)
+            else:
+                show_list(self.unchanged, 'S')
 
 
 @deprecated_function(zero_nine)

=== modified file bzrlib/status.py
--- bzrlib/status.py
+++ bzrlib/status.py
@@ -76,7 +76,8 @@
                      show_ids=False,
                      to_file=None,
                      show_pending=True,
-                     revision=None):
+                     revision=None,
+                     short=False):
     """Display summary of changes.
 
     By default this compares the working tree to a previous revision. 
@@ -101,6 +102,7 @@
         If not None it must be a RevisionSpec list.
         If one revision show compared it with working tree.
         If two revisions show status between first and second.
+    :param short: If True, gives short SVN-style status lines
     """
     if show_unchanged is not None:
         warn("show_status_trees with show_unchanged has been deprecated "
@@ -137,16 +139,23 @@
                               specific_files=specific_files)
         delta.show(to_file,
                    show_ids=show_ids,
-                   show_unchanged=show_unchanged)
-
-        list_paths('unknown', new.unknowns(), specific_files, to_file)
+                   show_unchanged=show_unchanged,
+                   short_status=short)
+        short_status_letter = '?'
+        if not short:
+            short_status_letter = ''
+        list_paths('unknown', new.unknowns(), specific_files, to_file,
+                   short_status_letter)
         conflict_title = False
         # show the new conflicts only for now. XXX: get them from the delta.
         for conflict in new.conflicts():
-            if conflict_title is False:
+            if not short and conflict_title is False:
                 print >> to_file, "conflicts:"
                 conflict_title = True
-            print >> to_file, "  %s" % conflict
+            if not short:
+                print >> to_file, "  %s" % conflict
+            else:
+                print >> to_file, "C  %s" % conflict
         if new_is_working_tree and show_pending:
             show_pending_merges(new, to_file)
     finally:
@@ -192,12 +201,12 @@
         except errors.NoSuchRevision:
             print >> to_file, ' ', merge
         
-def list_paths(header, paths, specific_files, to_file):
+def list_paths(header, paths, specific_files, to_file, short_status_letter=''):
     done_header = False
     for path in paths:
         if specific_files and not is_inside_any(specific_files, path):
             continue
-        if not done_header:
+        if not short_status_letter and not done_header:
             print >>to_file, '%s:' % header
             done_header = True
-        print >>to_file, ' ', path
+        print >>to_file, '%s %s' % (short_status_letter, path)

=== modified directory  // last-changed:keir at cs.utoronto.ca-20061122083620-jsqv
... usdnnxfmmvd3
# revision id: keir at cs.utoronto.ca-20061122083620-jsqvusdnnxfmmvd3
# sha1: d93f0ef207317215ab88b0ed56cec59f3c2952b7
# inventory sha1: e9ad112b70c92e3219c64903f377301381c3ff4e
# parent ids:
#   pqm at pqm.ubuntu.com-20061121123418-3d0b2fb05cbe6b43
# base id: pqm at pqm.ubuntu.com-20061121123418-3d0b2fb05cbe6b43
# properties:
#   branch-nick: bzr.shortstatus



More information about the bazaar mailing list