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

Proposed by Martin Packman
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~gz/brz/unmapped
Merge into: lp:brz
Prerequisite: lp:~gz/brz/i_unzipping
Diff against target: 444 lines (+56/-51)
24 files modified
breezy/btree_index.py (+6/-3)
breezy/dirstate.py (+2/-2)
breezy/export_pot.py (+1/-2)
breezy/groupcompress.py (+4/-1)
breezy/mutabletree.py (+1/-1)
breezy/osutils.py (+2/-1)
breezy/plugin.py (+2/-2)
breezy/plugins/changelog_merge/changelog_merge.py (+3/-3)
breezy/plugins/weave_fmt/bzrdir.py (+1/-1)
breezy/repository.py (+2/-2)
breezy/smart/repository.py (+2/-2)
breezy/tests/per_pack_repository.py (+1/-1)
breezy/tests/per_versionedfile.py (+4/-4)
breezy/tests/per_workingtree/test_paths2ids.py (+4/-4)
breezy/tests/test_diff.py (+4/-4)
breezy/tests/test_http.py (+2/-2)
breezy/tests/test_rio.py (+2/-2)
breezy/transport/memory.py (+2/-2)
breezy/transport/sftp.py (+1/-1)
breezy/util/simplemapi.py (+3/-4)
breezy/versionedfile.py (+3/-3)
breezy/vf_repository.py (+2/-2)
breezy/weave.py (+1/-1)
breezy/weavefile.py (+1/-1)
To merge this branch: bzr merge lp:~gz/brz/unmapped
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+324568@code.launchpad.net

This proposal supersedes a proposal from 2017-05-24.

Commit message

Make use of map Python 3 compatible

Description of the change

Cope with the builtin map function becoming imap in Python 3.

Worse case the fixer throws in an extra pointless list copy, where it looked like that might matter I refactored or pulled in the iterator version from future_builtins.

There are a few changes on somewhat hot paths, where larger refactors/rewrites are probably called for, but avoided doing so for now.

The static tuple intern change is somewhat driveby, we can't use sys.intern on bytestrings in Python 3 anyway, and a better interface would be constructing the tuple with a new method like from_bytes_interned or something to mega-intern the result.

Same as before just with prereq branch set correctly.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
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/btree_index.py'
2--- breezy/btree_index.py 2017-05-22 00:56:52 +0000
3+++ breezy/btree_index.py 2017-05-24 23:42:41 +0000
4@@ -42,6 +42,7 @@
5 from .index import _OPTION_NODE_REFS, _OPTION_KEY_ELEMENTS, _OPTION_LEN
6 from .sixish import (
7 BytesIO,
8+ map,
9 )
10
11
12@@ -662,7 +663,9 @@
13 for line in lines[2:]:
14 if line == '':
15 break
16- nodes.append(as_st(map(intern, line.split('\0'))).intern())
17+ # GZ 2017-05-24: Used to intern() each chunk of line as well, need
18+ # to recheck performance and perhaps adapt StaticTuple to adjust.
19+ nodes.append(as_st(line.split(b'\0')).intern())
20 return nodes
21
22
23@@ -1497,9 +1500,9 @@
24 if not options_line.startswith(_OPTION_ROW_LENGTHS):
25 raise errors.BadIndexOptions(self)
26 try:
27- self._row_lengths = map(int, [length for length in
28+ self._row_lengths = [int(length) for length in
29 options_line[len(_OPTION_ROW_LENGTHS):].split(',')
30- if len(length)])
31+ if length]
32 except ValueError:
33 raise errors.BadIndexOptions(self)
34 self._compute_row_offsets()
35
36=== modified file 'breezy/dirstate.py'
37--- breezy/dirstate.py 2017-05-22 11:22:28 +0000
38+++ breezy/dirstate.py 2017-05-24 23:42:41 +0000
39@@ -1953,7 +1953,7 @@
40 lines = []
41 lines.append(self._get_parents_line(self.get_parent_ids()))
42 lines.append(self._get_ghosts_line(self._ghosts))
43- lines.extend(self._get_entry_lines())
44+ lines.extend(self._iter_entry_lines())
45 return self._get_output_lines(lines)
46
47 def _get_ghosts_line(self, ghost_ids):
48@@ -1964,7 +1964,7 @@
49 """Create a line for the state file for parents information."""
50 return '\0'.join([str(len(parent_ids))] + parent_ids)
51
52- def _get_entry_lines(self):
53+ def _iter_entry_lines(self):
54 """Create lines for entries."""
55 return map(self._entry_to_line, self._iter_entries())
56
57
58=== modified file 'breezy/export_pot.py'
59--- breezy/export_pot.py 2017-05-22 00:56:52 +0000
60+++ breezy/export_pot.py 2017-05-24 23:42:41 +0000
61@@ -65,9 +65,8 @@
62 if not lines[-1]:
63 del lines[-1]
64 lines[-1] = lines[-1] + '\n'
65- lines = map(_escape, lines)
66 lineterm = '\\n"\n"'
67- s = '""\n"' + lineterm.join(lines) + '"'
68+ s = '""\n"' + lineterm.join(map(_escape, lines)) + '"'
69 return s
70
71
72
73=== modified file 'breezy/groupcompress.py'
74--- breezy/groupcompress.py 2017-05-22 00:56:52 +0000
75+++ breezy/groupcompress.py 2017-05-24 23:42:41 +0000
76@@ -42,6 +42,9 @@
77
78 from .btree_index import BTreeBuilder
79 from .lru_cache import LRUSizeCache
80+from .sixish import (
81+ map,
82+ )
83 from .versionedfile import (
84 _KeyRefs,
85 adapter_registry,
86@@ -300,7 +303,7 @@
87 compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION)
88 # Peak in this point is 1 fulltext, 1 compressed text, + zlib overhead
89 # (measured peak is maybe 30MB over the above...)
90- compressed_chunks = map(compressor.compress, chunks)
91+ compressed_chunks = list(map(compressor.compress, chunks))
92 compressed_chunks.append(compressor.flush())
93 # Ignore empty chunks
94 self._z_content_chunks = [c for c in compressed_chunks if c]
95
96=== modified file 'breezy/mutabletree.py'
97--- breezy/mutabletree.py 2017-05-22 00:56:52 +0000
98+++ breezy/mutabletree.py 2017-05-24 23:42:41 +0000
99@@ -667,7 +667,7 @@
100 # filename alone
101 # only expanding if symlinks are supported avoids windows path bugs
102 if osutils.has_symlinks():
103- file_list = map(osutils.normalizepath, file_list)
104+ file_list = list(map(osutils.normalizepath, file_list))
105
106 user_dirs = {}
107 # validate user file paths and convert all paths to tree
108
109=== modified file 'breezy/osutils.py'
110--- breezy/osutils.py 2017-05-22 00:56:52 +0000
111+++ breezy/osutils.py 2017-05-24 23:42:41 +0000
112@@ -811,7 +811,8 @@
113 def sha_strings(strings, _factory=sha):
114 """Return the sha-1 of concatenation of strings"""
115 s = _factory()
116- map(s.update, strings)
117+ for string in strings:
118+ s.update(string)
119 return s.hexdigest()
120
121
122
123=== modified file 'breezy/plugin.py'
124--- breezy/plugin.py 2017-05-22 00:56:52 +0000
125+++ breezy/plugin.py 2017-05-24 23:42:41 +0000
126@@ -266,7 +266,7 @@
127
128 # Get rid of trailing slashes, since Python can't handle them when
129 # it tries to import modules.
130- paths = map(_strip_trailing_sep, paths)
131+ paths = list(map(_strip_trailing_sep, paths))
132 return paths
133
134
135@@ -317,7 +317,7 @@
136 # this function, and since it sets plugins.__path__, it should set it to
137 # something that will be valid for Python to use (in case people try to
138 # run "import breezy.plugins.PLUGINNAME" after calling this function).
139- _mod_plugins.__path__ = map(_strip_trailing_sep, dirs)
140+ _mod_plugins.__path__ = list(map(_strip_trailing_sep, dirs))
141 for d in dirs:
142 if not d:
143 continue
144
145=== modified file 'breezy/plugins/changelog_merge/changelog_merge.py'
146--- breezy/plugins/changelog_merge/changelog_merge.py 2017-05-22 00:56:52 +0000
147+++ breezy/plugins/changelog_merge/changelog_merge.py 2017-05-24 23:42:41 +0000
148@@ -48,7 +48,7 @@
149 entries.append([])
150 entry = entries[-1]
151 entry.append(line)
152- return map(tuple, entries)
153+ return list(map(tuple, entries))
154
155
156 def entries_to_lines(entries):
157@@ -106,8 +106,8 @@
158 This algorithm does O(N^2 * logN) SequenceMatcher.ratio() calls, which is
159 pretty bad, but it shouldn't be used very often.
160 """
161- deleted_entries_as_strs = map(entry_as_str, deleted_entries)
162- new_entries_as_strs = map(entry_as_str, new_entries)
163+ deleted_entries_as_strs = list(map(entry_as_str, deleted_entries))
164+ new_entries_as_strs = list(map(entry_as_str, new_entries))
165 result_new = list(new_entries)
166 result_deleted = list(deleted_entries)
167 result_edits = []
168
169=== modified file 'breezy/plugins/weave_fmt/bzrdir.py'
170--- breezy/plugins/weave_fmt/bzrdir.py 2017-05-22 00:56:52 +0000
171+++ breezy/plugins/weave_fmt/bzrdir.py 2017-05-24 23:42:41 +0000
172@@ -415,7 +415,7 @@
173 Also upgrade the inventory to refer to the text revision ids."""
174 rev_id = rev.revision_id
175 trace.mutter('converting texts of revision {%s}', rev_id)
176- parent_invs = map(self._load_updated_inventory, present_parents)
177+ parent_invs = list(map(self._load_updated_inventory, present_parents))
178 entries = inv.iter_entries()
179 entries.next()
180 for path, ie in entries:
181
182=== modified file 'breezy/repository.py'
183--- breezy/repository.py 2017-05-22 00:56:52 +0000
184+++ breezy/repository.py 2017-05-24 23:42:41 +0000
185@@ -924,8 +924,8 @@
186 not part of revision_ids themselves
187 """
188 parent_map = self.get_parent_map(revision_ids)
189- parent_ids = set()
190- map(parent_ids.update, parent_map.itervalues())
191+ parent_ids = set(itertools.chain.from_iterable(
192+ parent_map.itervalues()))
193 parent_ids.difference_update(revision_ids)
194 parent_ids.discard(_mod_revision.NULL_REVISION)
195 return parent_ids
196
197=== modified file 'breezy/smart/repository.py'
198--- breezy/smart/repository.py 2017-05-22 00:56:52 +0000
199+++ breezy/smart/repository.py 2017-05-24 23:42:41 +0000
200@@ -19,6 +19,7 @@
201 from __future__ import absolute_import
202
203 import bz2
204+import itertools
205 import os
206 try:
207 import queue
208@@ -307,8 +308,7 @@
209 else:
210 search_ids = repository.all_revision_ids()
211 search = graph._make_breadth_first_searcher(search_ids)
212- transitive_ids = set()
213- map(transitive_ids.update, list(search))
214+ transitive_ids = set(itertools.chain.from_iterable(search))
215 parent_map = graph.get_parent_map(transitive_ids)
216 revision_graph = _strip_NULL_ghosts(parent_map)
217 if revision_id and revision_id not in revision_graph:
218
219=== modified file 'breezy/tests/per_pack_repository.py'
220--- breezy/tests/per_pack_repository.py 2017-05-23 14:08:03 +0000
221+++ breezy/tests/per_pack_repository.py 2017-05-24 23:42:41 +0000
222@@ -358,7 +358,7 @@
223 for _1, key, val, refs in pack.revision_index.iter_all_entries():
224 if isinstance(format.repository_format, RepositoryFormat2a):
225 # group_start, group_len, internal_start, internal_len
226- pos = map(int, val.split())
227+ pos = list(map(int, val.split()))
228 else:
229 # eol_flag, start, len
230 pos = int(val[1:].split()[0])
231
232=== modified file 'breezy/tests/per_versionedfile.py'
233--- breezy/tests/per_versionedfile.py 2017-05-24 23:30:47 +0000
234+++ breezy/tests/per_versionedfile.py 2017-05-24 23:42:41 +0000
235@@ -945,9 +945,9 @@
236 return x + '\n'
237
238 w = self.get_file()
239- w.add_lines('text0', [], map(addcrlf, base))
240- w.add_lines('text1', ['text0'], map(addcrlf, a))
241- w.add_lines('text2', ['text0'], map(addcrlf, b))
242+ w.add_lines('text0', [], list(map(addcrlf, base)))
243+ w.add_lines('text1', ['text0'], list(map(addcrlf, a)))
244+ w.add_lines('text2', ['text0'], list(map(addcrlf, b)))
245
246 self.log_contents(w)
247
248@@ -963,7 +963,7 @@
249 mt.seek(0)
250 self.log(mt.getvalue())
251
252- mp = map(addcrlf, mp)
253+ mp = list(map(addcrlf, mp))
254 self.assertEqual(mt.readlines(), mp)
255
256
257
258=== modified file 'breezy/tests/per_workingtree/test_paths2ids.py'
259--- breezy/tests/per_workingtree/test_paths2ids.py 2017-05-21 18:10:28 +0000
260+++ breezy/tests/per_workingtree/test_paths2ids.py 2017-05-24 23:42:41 +0000
261@@ -21,8 +21,6 @@
262 find_ids_across_trees.
263 """
264
265-from operator import attrgetter
266-
267 from breezy import errors
268 from breezy.tests import features
269 from breezy.tests.per_workingtree import TestCaseWithWorkingTree
270@@ -47,10 +45,12 @@
271 """Run paths2ids for tree, and check the result."""
272 tree.lock_read()
273 if trees:
274- map(apply, map(attrgetter('lock_read'), trees))
275+ for t in trees:
276+ t.lock_read()
277 result = tree.paths2ids(paths, trees,
278 require_versioned=require_versioned)
279- map(apply, map(attrgetter('unlock'), trees))
280+ for t in trees:
281+ t.unlock()
282 else:
283 result = tree.paths2ids(paths,
284 require_versioned=require_versioned)
285
286=== modified file 'breezy/tests/test_diff.py'
287--- breezy/tests/test_diff.py 2017-05-22 00:56:52 +0000
288+++ breezy/tests/test_diff.py 2017-05-24 23:42:41 +0000
289@@ -1194,8 +1194,8 @@
290 ]
291 , list(unified_diff(txt_a, txt_b,
292 sequencematcher=psm)))
293- txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop')
294- txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop')
295+ txt_a = [x+'\n' for x in 'abcdefghijklmnop']
296+ txt_b = [x+'\n' for x in 'abcdefxydefghijklmnop']
297 # This is the result with LongestCommonSubstring matching
298 self.assertEqual(['--- \n',
299 '+++ \n',
300@@ -1307,8 +1307,8 @@
301 , list(unified_diff_files('a1', 'b1',
302 sequencematcher=psm)))
303
304- txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop')
305- txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop')
306+ txt_a = [x+'\n' for x in 'abcdefghijklmnop']
307+ txt_b = [x+'\n' for x in 'abcdefxydefghijklmnop']
308 with open('a2', 'wb') as f: f.writelines(txt_a)
309 with open('b2', 'wb') as f: f.writelines(txt_b)
310
311
312=== modified file 'breezy/tests/test_http.py'
313--- breezy/tests/test_http.py 2017-05-22 00:56:52 +0000
314+++ breezy/tests/test_http.py 2017-05-24 23:42:41 +0000
315@@ -1391,8 +1391,8 @@
316
317 def test_range_header(self):
318 # Valid ranges
319- map(self.assertEqual,['0', '234'],
320- list(self._file_contents('a', [(0,0), (2,4)])),)
321+ self.assertEqual(
322+ ['0', '234'], list(self._file_contents('a', [(0,0), (2,4)])))
323
324 def test_range_header_tail(self):
325 self.assertEqual('789', self._file_tail('a', 3))
326
327=== modified file 'breezy/tests/test_rio.py'
328--- breezy/tests/test_rio.py 2017-05-21 18:10:28 +0000
329+++ breezy/tests/test_rio.py 2017-05-24 23:42:41 +0000
330@@ -130,8 +130,8 @@
331 s.add(k, v)
332 s2 = read_stanza(s.to_lines())
333 self.assertEqual(s, s2)
334- self.assertEqual(s.get_all('a'), map(str, [10, 100, 1000]))
335- self.assertEqual(s.get_all('b'), map(str, [20, 200, 2000]))
336+ self.assertEqual(s.get_all('a'), ['10', '100', '1000'])
337+ self.assertEqual(s.get_all('b'), ['20', '200', '2000'])
338
339 def test_backslash(self):
340 s = Stanza(q='\\')
341
342=== modified file 'breezy/transport/memory.py'
343--- breezy/transport/memory.py 2017-05-22 00:56:52 +0000
344+++ breezy/transport/memory.py 2017-05-24 23:42:41 +0000
345@@ -193,8 +193,8 @@
346 if path.startswith(_abspath):
347 trailing = path[len(_abspath):]
348 if trailing and '/' not in trailing:
349- result.append(trailing)
350- return map(urlutils.escape, result)
351+ result.append(urlutils.escape(trailing))
352+ return result
353
354 def rename(self, rel_from, rel_to):
355 """Rename a file or directory; fail if the destination exists"""
356
357=== modified file 'breezy/transport/sftp.py'
358--- breezy/transport/sftp.py 2017-05-24 23:30:47 +0000
359+++ breezy/transport/sftp.py 2017-05-24 23:42:41 +0000
360@@ -282,7 +282,7 @@
361 if data_chunks:
362 if 'sftp' in debug.debug_flags:
363 mutter('SFTP readv left with %d out-of-order bytes',
364- sum(map(lambda x: len(x[1]), data_chunks)))
365+ sum(len(x[1]) for x in data_chunks))
366 # We've processed all the readv data, at this point, anything we
367 # couldn't process is in data_chunks. This doesn't happen often, so
368 # this code path isn't optimized
369
370=== modified file 'breezy/util/simplemapi.py'
371--- breezy/util/simplemapi.py 2017-02-05 16:35:58 +0000
372+++ breezy/util/simplemapi.py 2017-05-24 23:42:41 +0000
373@@ -233,10 +233,9 @@
374
375 attach = []
376 AttachWork = attachfiles.split(';')
377- for file in AttachWork:
378- if os.path.exists(file):
379- attach.append(file)
380- attach = map(os.path.abspath, attach)
381+ for f in AttachWork:
382+ if os.path.exists(f):
383+ attach.append(os.path.abspath(f))
384
385 restore = os.getcwd()
386 try:
387
388=== modified file 'breezy/versionedfile.py'
389--- breezy/versionedfile.py 2017-05-24 23:42:40 +0000
390+++ breezy/versionedfile.py 2017-05-24 23:42:41 +0000
391@@ -1093,9 +1093,9 @@
392 while pending:
393 this_parent_map = self.get_parent_map(pending)
394 parent_map.update(this_parent_map)
395- pending = set()
396- map(pending.update, this_parent_map.itervalues())
397- pending = pending.difference(parent_map)
398+ pending = set(itertools.chain.from_iterable(
399+ this_parent_map.itervalues()))
400+ pending.difference_update(parent_map)
401 kg = _mod_graph.KnownGraph(parent_map)
402 return kg
403
404
405=== modified file 'breezy/vf_repository.py'
406--- breezy/vf_repository.py 2017-05-22 00:56:52 +0000
407+++ breezy/vf_repository.py 2017-05-24 23:42:41 +0000
408@@ -1516,8 +1516,8 @@
409 revision_keys
410 """
411 parent_map = self.revisions.get_parent_map(revision_keys)
412- parent_keys = set()
413- map(parent_keys.update, parent_map.itervalues())
414+ parent_keys = set(itertools.chain.from_iterable(
415+ parent_map.itervalues()))
416 parent_keys.difference_update(revision_keys)
417 parent_keys.discard(_mod_revision.NULL_REVISION)
418 return parent_keys
419
420=== modified file 'breezy/weave.py'
421--- breezy/weave.py 2017-05-22 00:56:52 +0000
422+++ breezy/weave.py 2017-05-24 23:42:41 +0000
423@@ -393,7 +393,7 @@
424 def _add_lines(self, version_id, parents, lines, parent_texts,
425 left_matching_blocks, nostore_sha, random_id, check_content):
426 """See VersionedFile.add_lines."""
427- idx = self._add(version_id, lines, map(self._lookup, parents),
428+ idx = self._add(version_id, lines, list(map(self._lookup, parents)),
429 nostore_sha=nostore_sha)
430 return sha_strings(lines), sum(map(len, lines)), idx
431
432
433=== modified file 'breezy/weavefile.py'
434--- breezy/weavefile.py 2017-05-22 00:56:52 +0000
435+++ breezy/weavefile.py 2017-05-24 23:42:41 +0000
436@@ -135,7 +135,7 @@
437 l = lines.next()
438 if l[0] == 'i':
439 if len(l) > 2:
440- w._parents.append(map(int, l[2:].split(' ')))
441+ w._parents.append(list(map(int, l[2:].split(' '))))
442 else:
443 w._parents.append([])
444 l = lines.next()[:-1]

Subscribers

People subscribed via source and target branches