Rev 3883: Add a 'path_filter' parameter to delta.show(). in file:///net/bigmamac/Volumes/home/vila/src/bzr/cases/3232-spurious-conflict/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Dec 10 08:44:05 GMT 2008


At file:///net/bigmamac/Volumes/home/vila/src/bzr/cases/3232-spurious-conflict/

------------------------------------------------------------
revno: 3883
revision-id: v.ladeuil+lp at free.fr-20081210084403-89803az7m7rysrsy
parent: v.ladeuil+lp at free.fr-20081209085755-z6wcpmi9xa3uazm8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: delta-show-with-path-filter
timestamp: Wed 2008-12-10 09:44:03 +0100
message:
  Add a 'path_filter' parameter to delta.show().
  
  * bzrlib/tests/test_delta.py:
  (TestDeltaShow): Tests for delta.show() and the new 'path_filter'
  parameter.
  
  * bzrlib/delta.py:
  (TreeDelta.show.show_list): Display header only once, before first
  file is displayed. Add a path_filter parameter. Add doc_string.
-------------- next part --------------
=== modified file 'bzrlib/delta.py'
--- a/bzrlib/delta.py	2008-12-08 15:57:57 +0000
+++ b/bzrlib/delta.py	2008-12-10 08:44:03 +0000
@@ -109,8 +109,24 @@
 
 
     def show(self, to_file, show_ids=False, show_unchanged=False,
-             short_status=False, indent=''):
-        """output this delta in status-like form to to_file."""
+             short_status=False, indent='',
+             path_filter=None):
+        """Output this delta in status-like form to to_file.
+
+        :param to_file: A file-like object where the output is displayed.
+
+        :param show_ids: Output the file ids if True.
+
+        :param show_unchanged: Output the unchanged files if True.
+
+        :param short_status: Single-line status if True.
+
+        :param indent: Added at the beginning of all output lines (for merged
+            revisions).
+
+        :param path_filter: A callable recieving a path and returning True if
+            the path should be displayed.
+        """
 
         def decorate_path(path, kind, meta_modified=None):
             if kind == 'directory':
@@ -146,15 +162,20 @@
                       default_format='%s', with_file_id_format='%-30s',
                       show_more=None):
             if files:
+                header_shown = False
                 if short_status:
                     prefix = short_status_letter
                 else:
-                    to_file.write(indent + long_status_name + ':\n')
                     prefix = ''
                 prefix = indent + prefix + '  '
 
                 for item in files:
                     path, file_id, kind = item[:3]
+                    if (path_filter is not None and not path_filter(path)):
+                        continue
+                    if not header_shown and not short_status:
+                        to_file.write(indent + long_status_name + ':\n')
+                        header_shown = True
                     meta_modified = None
                     if len(item) == 5:
                         meta_modified = item[4]

=== modified file 'bzrlib/tests/test_delta.py'
--- a/bzrlib/tests/test_delta.py	2007-03-07 23:15:10 +0000
+++ b/bzrlib/tests/test_delta.py	2008-12-10 08:44:03 +0000
@@ -15,10 +15,11 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import os
-from StringIO import StringIO
+from cStringIO import StringIO
 
 from bzrlib import (
     delta as _mod_delta,
+    revision as _mod_revision,
     tests,
     )
 
@@ -187,7 +188,7 @@
                            exe_change=False)
 
 
-class TestChangesFrom (tests.TestCaseWithTransport):
+class TestChangesFrom(tests.TestCaseWithTransport):
 
     def show_string(self, delta, *args,  **kwargs):
         to_file = StringIO()
@@ -238,3 +239,72 @@
                            True, False)], delta.renamed)
         self.assertTrue(delta.has_changed())
         self.assertTrue(delta.touches_file_id('file-id'))
+
+
+class TestDeltaShow(tests.TestCaseWithTransport):
+
+    def _get_delta(self):
+        # We build the delta from a real tree to avoid depending on internal
+        # implementation details.
+        wt = self.make_branch_and_tree('branch')
+        self.build_tree_contents([('branch/f1', '1\n'),
+                                  ('branch/f2', '2\n'),
+                                  ('branch/f3', '3\n'),
+                                  ('branch/f4', '4\n'),
+                                  ('branch/dir/',),
+                                 ])
+        wt.add(['f1', 'f2', 'f3', 'f4', 'dir'],
+               ['f1-id', 'f2-id', 'f3-id', 'f4-id', 'dir-id'])
+        wt.commit('commit one', rev_id='1')
+
+        long_status = """added:
+  f1
+  f2
+  f3
+  f4
+"""
+        short_status = """A  f1
+A  f2
+A  f3
+A  f4
+"""
+
+        repo = wt.branch.repository
+        d = wt.changes_from(repo.revision_tree(_mod_revision.NULL_REVISION))
+        return d, long_status, short_status
+
+    def test_delta_show_short_status_no_filter(self):
+        d, long_status, short_status = self._get_delta()
+        out = StringIO()
+        d.show(out, short_status=True)
+        self.assertEquals(short_status, out.getvalue())
+
+    def test_delta_show_long_status_no_filter(self):
+        d, long_status, short_status = self._get_delta()
+        out = StringIO()
+        d.show(out, short_status=False)
+        self.assertEquals(long_status, out.getvalue())
+
+    def test_delta_show_no_filter(self):
+        d, long_status, short_status = self._get_delta()
+        out = StringIO()
+        def not_a_filter(path):
+            return True
+        d.show(out, short_status=True, path_filter=not_a_filter)
+        self.assertEquals(short_status, out.getvalue())
+
+    def test_delta_show_short_status_single_file_filter(self):
+        d, long_status, short_status = self._get_delta()
+        out = StringIO()
+        def only_f2(path):
+            return path == 'f2'
+        d.show(out, short_status=True, path_filter=only_f2)
+        self.assertEquals("A  f2\n", out.getvalue())
+
+    def test_delta_show_long_status_single_file_filter(self):
+        d, long_status, short_status = self._get_delta()
+        out = StringIO()
+        def only_f2(path):
+            return path == 'f2'
+        d.show(out, short_status=False, path_filter=only_f2)
+        self.assertEquals("added:\n  f2\n", out.getvalue())



More information about the bazaar-commits mailing list