[Pkg-bazaar-commits] ./bzr/unstable r465: - Move show_status() out of Branch into a new function in
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:19:08 UTC 2009
------------------------------------------------------------
revno: 465
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Wed 2005-05-11 15:55:27 +1000
message:
- Move show_status() out of Branch into a new function in
bzrlib.status
- New option --show-ids for status command
- Refactor TreeDelta.show()
and add optional support for showing unmodified files
- Changed output format for status command
modified:
NEWS
bzrlib/branch.py
bzrlib/commands.py
bzrlib/diff.py
bzrlib/status.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2005-05-11 00:56:49 +0000
+++ b/NEWS 2005-05-11 05:55:27 +0000
@@ -5,6 +5,11 @@
* ``bzr`` with no command now shows help rather than giving an
error. Suggested by Michael Ellerman.
+ * ``bzr status`` output format changed, because svn-style output
+ doesn't really match the model of bzr. Now files are grouped by
+ status and can be shown with their IDs. ``bzr status --all``
+ shows all versioned files and unknown files but not ignored files.
+
ENHANCEMENTS:
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2005-05-11 02:27:13 +0000
+++ b/bzrlib/branch.py 2005-05-11 05:55:27 +0000
@@ -923,62 +923,6 @@
- def show_status(self, show_all=False, file_list=None):
- """Display single-line status for non-ignored working files.
-
- The list is show sorted in order by file name.
-
- >>> b = ScratchBranch(files=['foo', 'foo~'])
- >>> b.show_status()
- ? foo
- >>> b.add('foo')
- >>> b.show_status()
- A foo
- >>> b.commit("add foo")
- >>> b.show_status()
- >>> os.unlink(b.abspath('foo'))
- >>> b.show_status()
- D foo
- """
- self._need_readlock()
-
- # We have to build everything into a list first so that it can
- # sorted by name, incorporating all the different sources.
-
- # FIXME: Rather than getting things in random order and then sorting,
- # just step through in order.
-
- # Interesting case: the old ID for a file has been removed,
- # but a new file has been created under that name.
-
- old = self.basis_tree()
- new = self.working_tree()
-
- items = diff_trees(old, new)
- # We want to filter out only if any file was provided in the file_list.
- if isinstance(file_list, list) and len(file_list):
- items = [item for item in items if item[3] in file_list]
-
- for fs, fid, oldname, newname, kind in items:
- if fs == 'R':
- show_status(fs, kind,
- oldname + ' => ' + newname)
- elif fs == 'A' or fs == 'M':
- show_status(fs, kind, newname)
- elif fs == 'D':
- show_status(fs, kind, oldname)
- elif fs == '.':
- if show_all:
- show_status(fs, kind, newname)
- elif fs == 'I':
- if show_all:
- show_status(fs, kind, newname)
- elif fs == '?':
- show_status(fs, kind, newname)
- else:
- bailout("weird file state %r" % ((fs, fid),))
-
-
class ScratchBranch(Branch):
"""Special test class: a branch that cleans up after itself.
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2005-05-11 04:18:51 +0000
+++ b/bzrlib/commands.py 2005-05-11 05:55:27 +0000
@@ -194,12 +194,14 @@
missing, in which case the old name is shown.
"""
takes_args = ['file*']
- takes_options = ['all']
+ takes_options = ['all', 'show-ids']
aliases = ['st', 'stat']
- def run(self, all=False, file_list=None):
+ def run(self, all=False, show_ids=False, file_list=None):
b = Branch('.', lock_mode='r')
- b.show_status(show_all=all, file_list=file_list)
+ import status
+ status.show_status(b, show_unchanged=all, show_ids=show_ids,
+ file_list=file_list)
class cmd_cat_revision(Command):
=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py 2005-05-11 05:02:35 +0000
+++ b/bzrlib/diff.py 2005-05-11 05:55:27 +0000
@@ -276,21 +276,22 @@
self.modified = []
self.unchanged = []
- def show(self, to_file, show_ids):
+ def show(self, to_file, show_ids=False, show_unchanged=False):
+ def show_list(files):
+ for path, fid in files:
+ if show_ids:
+ print >>to_file, ' %-30s %s' % (path, fid)
+ else:
+ print >>to_file, ' ', path
+
if self.removed:
print >>to_file, 'removed files:'
- for path, fid in self.removed:
- if show_ids:
- print >>to_file, ' %-30s %s' % (path, fid)
- else:
- print >>to_file, ' ', path
+ show_list(self.removed)
+
if self.added:
print >>to_file, 'added files:'
- for path, fid in self.added:
- if show_ids:
- print >>to_file, ' %-30s %s' % (path, fid)
- else:
- print >>to_file, ' ' + path
+ show_list(self.added)
+
if self.renamed:
print >>to_file, 'renamed files:'
for oldpath, newpath, fid, text_modified in self.renamed:
@@ -298,13 +299,14 @@
print >>to_file, ' %s => %s %s' % (oldpath, newpath, fid)
else:
print >>to_file, ' %s => %s' % (oldpath, newpath)
+
if self.modified:
print >>to_file, 'modified files:'
- for path, fid in self.modified:
- if show_ids:
- print >>to_file, ' %-30s %s' % (path, fid)
- else:
- print >>to_file, ' ' + path
+ show_list(self.modified)
+
+ if show_unchanged and self.unchanged:
+ print >>to_file, 'unchanged files:'
+ show_list(self.unchanged)
=== modified file 'bzrlib/status.py'
--- a/bzrlib/status.py 2005-05-11 05:15:13 +0000
+++ b/bzrlib/status.py 2005-05-11 05:55:27 +0000
@@ -15,3 +15,39 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+def show_status(branch, show_unchanged=False,
+ file_list=None,
+ show_ids=False):
+ """Display single-line status for non-ignored working files.
+
+ show_all
+ If true, show unmodified files too.
+
+ file_list
+ If set, only show the status of files in this list.
+ """
+ import sys
+ import diff
+
+ branch._need_readlock()
+
+ old = branch.basis_tree()
+ new = branch.working_tree()
+
+ if file_list:
+ raise NotImplementedError("sorry, status on selected files is not implemented "
+ "at the moment")
+
+ delta = diff.compare_trees(old, new)
+
+ delta.show(sys.stdout, show_ids=show_ids,
+ show_unchanged=show_unchanged)
+
+ unknowns = new.unknowns()
+ done_header = False
+ for path in unknowns:
+ if not done_header:
+ print 'unknown files:'
+ done_header = True
+ print ' ', path
More information about the Pkg-bazaar-commits
mailing list