Merge lp:~gz/brz/unfiltered into lp:brz

Proposed by Martin Packman on 2017-05-24
Status: Merged
Approved by: Martin Packman on 2017-05-25
Approved revision: 6635
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~gz/brz/unfiltered
Merge into: lp:brz
Prerequisite: lp:~gz/brz/i_unzipping
Diff against target: 162 lines (+30/-27)
5 files modified
breezy/delta.py (+5/-4)
breezy/log.py (+1/-1)
breezy/tests/http_server.py (+1/-2)
breezy/tests/test_delta.py (+20/-20)
doc/en/release-notes/brz-3.0.txt (+3/-0)
To merge this branch: bzr merge lp:~gz/brz/unfiltered
Reviewer Review Type Date Requested Status
Jelmer Vernooij 2017-05-24 Approve on 2017-05-24
Review via email: mp+324570@code.launchpad.net

Commit message

Remove some uses of filter that confused things

Description of the change

This started as just running the 2to3 filter fixer, but ended up with a parameter rename (not used outside of tests) and some slight changes to `filter(None, ...)` constructs.

So, now Python 3 compatible but not quite how the fixer envisioned.

To post a comment you must log in.
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/delta.py'
2--- breezy/delta.py 2017-05-22 00:56:52 +0000
3+++ breezy/delta.py 2017-05-24 20:51:57 +0000
4@@ -349,8 +349,9 @@
5 reporter.report(file_id, path, versioned_change, renamed, modified,
6 exe_change, kind)
7
8-def report_delta(to_file, delta, short_status=False, show_ids=False,
9- show_unchanged=False, indent='', filter=None, classify=True):
10+
11+def report_delta(to_file, delta, short_status=False, show_ids=False,
12+ show_unchanged=False, indent='', predicate=None, classify=True):
13 """Output this delta in status-like form to to_file.
14
15 :param to_file: A file-like object where the output is displayed.
16@@ -366,7 +367,7 @@
17 :param indent: Added at the beginning of all output lines (for merged
18 revisions).
19
20- :param filter: A callable receiving a path and a file id and
21+ :param predicate: A callable receiving a path and a file id and
22 returning True if the path should be displayed.
23
24 :param classify: Add special symbols to indicate file kind.
25@@ -417,7 +418,7 @@
26
27 for item in files:
28 path, file_id, kind = item[:3]
29- if (filter is not None and not filter(path, file_id)):
30+ if (predicate is not None and not predicate(path, file_id)):
31 continue
32 if not header_shown and not short_status:
33 to_file.write(indent + long_status_name + ':\n')
34
35=== modified file 'breezy/log.py'
36--- breezy/log.py 2017-05-24 20:51:57 +0000
37+++ breezy/log.py 2017-05-24 20:51:57 +0000
38@@ -889,7 +889,7 @@
39 return True
40
41 def _match_any_filter(strings, res):
42- return any([filter(None, map(re.search, strings)) for re in res])
43+ return any(re.search(s) for re in res for s in strings)
44
45 def _make_delta_filter(branch, generate_delta, search, log_rev_iterator,
46 fileids=None, direction='reverse'):
47
48=== modified file 'breezy/tests/http_server.py'
49--- breezy/tests/http_server.py 2017-05-22 00:56:52 +0000
50+++ breezy/tests/http_server.py 2017-05-24 20:51:57 +0000
51@@ -342,9 +342,8 @@
52 path = posixpath.normpath(urlutils.unquote(path))
53 path = path.decode('utf-8')
54 words = path.split('/')
55- words = filter(None, words)
56 path = self._cwd
57- for num, word in enumerate(words):
58+ for num, word in enumerate(w for w in words if w):
59 if num == 0:
60 drive, word = os.path.splitdrive(word)
61 head, word = os.path.split(word)
62
63=== modified file 'breezy/tests/test_delta.py'
64--- breezy/tests/test_delta.py 2017-05-22 00:56:52 +0000
65+++ breezy/tests/test_delta.py 2017-05-24 20:51:57 +0000
66@@ -22,7 +22,7 @@
67 tests,
68 )
69 from ..sixish import (
70- BytesIO,
71+ StringIO,
72 )
73
74
75@@ -227,7 +227,7 @@
76 class TestChangesFrom(tests.TestCaseWithTransport):
77
78 def show_string(self, delta, *args, **kwargs):
79- to_file = BytesIO()
80+ to_file = StringIO()
81 _mod_delta.report_delta(to_file, delta, *args, **kwargs)
82 return to_file.getvalue()
83
84@@ -319,47 +319,47 @@
85 d = wt.changes_from(repo.revision_tree(_mod_revision.NULL_REVISION))
86 return d, long_status, short_status
87
88- def test_delta_show_short_status_no_filter(self):
89+ def test_short_status(self):
90 d, long_status, short_status = self._get_delta()
91- out = BytesIO()
92+ out = StringIO()
93 _mod_delta.report_delta(out, d, short_status=True)
94 self.assertEqual(short_status, out.getvalue())
95
96- def test_delta_show_long_status_no_filter(self):
97+ def test_long_status(self):
98 d, long_status, short_status = self._get_delta()
99- out = BytesIO()
100+ out = StringIO()
101 _mod_delta.report_delta(out, d, short_status=False)
102 self.assertEqual(long_status, out.getvalue())
103
104- def test_delta_show_no_filter(self):
105+ def test_predicate_always(self):
106 d, long_status, short_status = self._get_delta()
107- out = BytesIO()
108- def not_a_filter(path, file_id):
109+ out = StringIO()
110+ def always(path, file_id):
111 return True
112- _mod_delta.report_delta(out, d, short_status=True, filter=not_a_filter)
113+ _mod_delta.report_delta(out, d, short_status=True, predicate=always)
114 self.assertEqual(short_status, out.getvalue())
115
116- def test_delta_show_short_status_single_file_filter(self):
117+ def test_short_status_path_predicate(self):
118 d, long_status, short_status = self._get_delta()
119- out = BytesIO()
120+ out = StringIO()
121 def only_f2(path, file_id):
122 return path == 'f2'
123- _mod_delta.report_delta(out, d, short_status=True, filter=only_f2)
124+ _mod_delta.report_delta(out, d, short_status=True, predicate=only_f2)
125 self.assertEqual("A f2\n", out.getvalue())
126
127- def test_delta_show_long_status_single_file_filter(self):
128+ def test_long_status_path_predicate(self):
129 d, long_status, short_status = self._get_delta()
130- out = BytesIO()
131+ out = StringIO()
132 def only_f2(path, file_id):
133 return path == 'f2'
134- _mod_delta.report_delta(out, d, short_status=False, filter=only_f2)
135+ _mod_delta.report_delta(out, d, short_status=False, predicate=only_f2)
136 self.assertEqual("added:\n f2\n", out.getvalue())
137
138- def test_delta_show_short_status_single_file_id_filter(self):
139+ def test_long_status_id_predicate(self):
140 d, long_status, short_status = self._get_delta()
141- out = BytesIO()
142+ out = StringIO()
143 def only_f2_id(path, file_id):
144 return file_id == 'f2-id'
145- _mod_delta.report_delta(out, d, short_status=True, filter=only_f2_id)
146- self.assertEqual("A f2\n", out.getvalue())
147+ _mod_delta.report_delta(out, d, predicate=only_f2_id)
148+ self.assertEqual("added:\n f2\n", out.getvalue())
149
150
151=== modified file 'doc/en/release-notes/brz-3.0.txt'
152--- doc/en/release-notes/brz-3.0.txt 2017-05-24 00:57:47 +0000
153+++ doc/en/release-notes/brz-3.0.txt 2017-05-24 20:51:57 +0000
154@@ -55,6 +55,9 @@
155 * Signature of ``load_tests`` used by ``TestLoader`` changed to be
156 compatible with standard libarary unittest. (Martin Packman)
157
158+ * Renamed ``breezy.delta.report_delta`` parameter ``filter=`` to
159+ ``predicate=``. (Martin Packman)
160+
161 Internals
162 *********
163

Subscribers

People subscribed via source and target branches