Merge lp:~jelmer/brz/inventory-chunks into lp:brz
- inventory-chunks
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Approved by: | Jelmer Vernooij |
Approved revision: | no longer in the source branch. |
Merge reported by: | The Breezy Bot |
Merged at revision: | not available |
Proposed branch: | lp:~jelmer/brz/inventory-chunks |
Merge into: | lp:brz |
Diff against target: |
1081 lines (+199/-209) 19 files modified
breezy/bzr/bundle/bundle_data.py (+4/-4) breezy/bzr/bundle/serializer/v4.py (+12/-13) breezy/bzr/chk_serializer.py (+6/-12) breezy/bzr/groupcompress_repo.py (+14/-14) breezy/bzr/inventory.py (+5/-7) breezy/bzr/serializer.py (+31/-22) breezy/bzr/vf_repository.py (+19/-19) breezy/bzr/workingtree.py (+11/-11) breezy/bzr/xml8.py (+2/-9) breezy/bzr/xml_serializer.py (+9/-7) breezy/plugins/weave_fmt/bzrdir.py (+11/-10) breezy/tests/per_pack_repository.py (+2/-2) breezy/tests/per_repository_reference/test_fetch.py (+2/-2) breezy/tests/per_workingtree/test_basis_inventory.py (+3/-3) breezy/tests/test_bundle.py (+2/-2) breezy/tests/test_inv.py (+29/-29) breezy/tests/test_remote.py (+3/-3) breezy/tests/test_repository.py (+3/-3) breezy/tests/test_xml.py (+31/-37) |
To merge this branch: | bzr merge lp:~jelmer/brz/inventory-chunks |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jelmer Vernooij | Approve | ||
Review via email: mp+378341@code.launchpad.net |
Commit message
Use chunks rather than fulltexts for inventories where possible.
Description of the change
Use chunks rather than fulltexts for inventories where possible.
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) : | # |
review:
Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'breezy/bzr/bundle/bundle_data.py' |
2 | --- breezy/bzr/bundle/bundle_data.py 2020-01-19 13:47:29 +0000 |
3 | +++ breezy/bzr/bundle/bundle_data.py 2020-01-30 16:35:32 +0000 |
4 | @@ -40,7 +40,7 @@ |
5 | InventoryFile, |
6 | InventoryLink, |
7 | ) |
8 | -from ...osutils import sha_string, pathjoin |
9 | +from ...osutils import sha_string, sha_strings, pathjoin |
10 | from ...revision import Revision, NULL_REVISION |
11 | from ...sixish import ( |
12 | viewitems, |
13 | @@ -286,15 +286,15 @@ |
14 | so build up an inventory, and make sure the hashes match. |
15 | """ |
16 | # Now we should have a complete inventory entry. |
17 | - s = serializer_v5.write_inventory_to_string(inv) |
18 | - sha1 = sha_string(s) |
19 | + cs = serializer_v5.write_inventory_to_chunks(inv) |
20 | + sha1 = sha_strings(cs) |
21 | # Target revision is the last entry in the real_revisions list |
22 | rev = self.get_revision(revision_id) |
23 | if rev.revision_id != revision_id: |
24 | raise AssertionError() |
25 | if sha1 != rev.inventory_sha1: |
26 | with open(',,bogus-inv', 'wb') as f: |
27 | - f.write(s) |
28 | + f.writelines(cs) |
29 | warning('Inventory sha hash mismatch for revision %s. %s' |
30 | ' != %s' % (revision_id, sha1, rev.inventory_sha1)) |
31 | |
32 | |
33 | === modified file 'breezy/bzr/bundle/serializer/v4.py' |
34 | --- breezy/bzr/bundle/serializer/v4.py 2019-06-30 10:50:40 +0000 |
35 | +++ breezy/bzr/bundle/serializer/v4.py 2020-01-30 16:35:32 +0000 |
36 | @@ -62,7 +62,7 @@ |
37 | # parents first, and then grab the ordered requests. |
38 | needed_ids = [k[-1] for k in self.present_parents] |
39 | needed_ids.extend([k[-1] for k in self.ordered_keys]) |
40 | - inv_to_bytes = self.repo._serializer.write_inventory_to_string |
41 | + inv_to_lines = self.repo._serializer.write_inventory_to_chunks |
42 | for inv in self.repo.iter_inventories(needed_ids): |
43 | revision_id = inv.revision_id |
44 | key = (revision_id,) |
45 | @@ -72,12 +72,12 @@ |
46 | parent_ids = None |
47 | else: |
48 | parent_ids = [k[-1] for k in self.parent_map[key]] |
49 | - as_bytes = inv_to_bytes(inv) |
50 | - self._process_one_record(key, (as_bytes,)) |
51 | + as_chunks = inv_to_lines(inv) |
52 | + self._process_one_record(key, as_chunks) |
53 | if parent_ids is None: |
54 | continue |
55 | diff = self.diffs.pop(key) |
56 | - sha1 = osutils.sha_string(as_bytes) |
57 | + sha1 = osutils.sha_strings(as_chunks) |
58 | yield revision_id, parent_ids, sha1, diff |
59 | |
60 | |
61 | @@ -368,7 +368,7 @@ |
62 | """Generate mpdiffs by serializing inventories. |
63 | |
64 | The current repository only has part of the tree shape information in |
65 | - the 'inventories' vf. So we use serializer.write_inventory_to_string to |
66 | + the 'inventories' vf. So we use serializer.write_inventory_to_lines to |
67 | get a 'full' representation of the tree shape, and then generate |
68 | mpdiffs on that data stream. This stream can then be reconstructed on |
69 | the other side. |
70 | @@ -626,10 +626,10 @@ |
71 | present_parent_ids.append(p_id) |
72 | else: |
73 | ghosts.add(p_id) |
74 | - to_string = self._source_serializer.write_inventory_to_string |
75 | + to_lines = self._source_serializer.write_inventory_to_chunks |
76 | for parent_inv in self._repository.iter_inventories( |
77 | present_parent_ids): |
78 | - p_text = to_string(parent_inv) |
79 | + p_text = b''.join(to_lines(parent_inv)) |
80 | inventory_cache[parent_inv.revision_id] = parent_inv |
81 | cached_parent_texts[parent_inv.revision_id] = p_text |
82 | inventory_text_cache[parent_inv.revision_id] = p_text |
83 | @@ -670,15 +670,14 @@ |
84 | # as lines and then cast back to a string. |
85 | target_lines = multiparent.MultiParent.from_patch(bytes |
86 | ).to_lines(p_texts) |
87 | - inv_text = b''.join(target_lines) |
88 | - del target_lines |
89 | - sha1 = osutils.sha_string(inv_text) |
90 | + sha1 = osutils.sha_strings(target_lines) |
91 | if sha1 != metadata[b'sha1']: |
92 | raise errors.BadBundle("Can't convert to target format") |
93 | # Add this to the cache so we don't have to extract it again. |
94 | - inventory_text_cache[revision_id] = inv_text |
95 | - target_inv = self._source_serializer.read_inventory_from_string( |
96 | - inv_text) |
97 | + inventory_text_cache[revision_id] = b''.join(target_lines) |
98 | + target_inv = self._source_serializer.read_inventory_from_lines( |
99 | + target_lines) |
100 | + del target_lines |
101 | self._handle_root(target_inv, parent_ids) |
102 | parent_inv = None |
103 | if parent_ids: |
104 | |
105 | === modified file 'breezy/bzr/chk_serializer.py' |
106 | --- breezy/bzr/chk_serializer.py 2018-11-11 04:08:32 +0000 |
107 | +++ breezy/bzr/chk_serializer.py 2020-01-30 16:35:32 +0000 |
108 | @@ -162,8 +162,8 @@ |
109 | return_from_cache) |
110 | return inv |
111 | |
112 | - def read_inventory_from_string(self, xml_string, revision_id=None, |
113 | - entry_cache=None, return_from_cache=False): |
114 | + def read_inventory_from_lines(self, xml_lines, revision_id=None, |
115 | + entry_cache=None, return_from_cache=False): |
116 | """Read xml_string into an inventory object. |
117 | |
118 | :param xml_string: The xml to read. |
119 | @@ -179,7 +179,7 @@ |
120 | """ |
121 | try: |
122 | return self._unpack_inventory( |
123 | - xml_serializer.fromstring(xml_string), revision_id, |
124 | + xml_serializer.fromstringlist(xml_lines), revision_id, |
125 | entry_cache=entry_cache, |
126 | return_from_cache=return_from_cache) |
127 | except xml_serializer.ParseError as e: |
128 | @@ -200,15 +200,9 @@ |
129 | """Return a list of lines with the encoded inventory.""" |
130 | return self.write_inventory(inv, None) |
131 | |
132 | - def write_inventory_to_string(self, inv, working=False): |
133 | - """Just call write_inventory with a BytesIO and return the value. |
134 | - |
135 | - :param working: If True skip history data - text_sha1, text_size, |
136 | - reference_revision, symlink_target. |
137 | - """ |
138 | - sio = BytesIO() |
139 | - self.write_inventory(inv, sio, working) |
140 | - return sio.getvalue() |
141 | + def write_inventory_to_chunks(self, inv): |
142 | + """Return a list of lines with the encoded inventory.""" |
143 | + return self.write_inventory(inv, None) |
144 | |
145 | def write_inventory(self, inv, f, working=False): |
146 | """Write inventory to a file. |
147 | |
148 | === modified file 'breezy/bzr/groupcompress_repo.py' |
149 | --- breezy/bzr/groupcompress_repo.py 2020-01-25 14:07:41 +0000 |
150 | +++ breezy/bzr/groupcompress_repo.py 2020-01-30 16:35:32 +0000 |
151 | @@ -234,9 +234,9 @@ |
152 | stream = source_vf.get_record_stream(keys, 'groupcompress', True) |
153 | for idx, record in enumerate(stream): |
154 | # Inventories should always be with revisions; assume success. |
155 | - bytes = record.get_bytes_as('fulltext') |
156 | - chk_inv = inventory.CHKInventory.deserialise(None, bytes, |
157 | - record.key) |
158 | + lines = record.get_bytes_as('lines') |
159 | + chk_inv = inventory.CHKInventory.deserialise( |
160 | + None, lines, record.key) |
161 | if pb is not None: |
162 | pb.update('inv', idx, total_keys) |
163 | key = chk_inv.id_to_entry.key() |
164 | @@ -664,9 +664,9 @@ |
165 | search_key_name = None |
166 | for idx, record in enumerate(stream): |
167 | # Inventories should always be with revisions; assume success. |
168 | - bytes = record.get_bytes_as('fulltext') |
169 | + lines = record.get_bytes_as('lines') |
170 | chk_inv = inventory.CHKInventory.deserialise( |
171 | - source_chk_vf, bytes, record.key) |
172 | + source_chk_vf, lines, record.key) |
173 | if pb is not None: |
174 | pb.update('inv', idx, total_keys) |
175 | chk_inv.id_to_entry._ensure_root() |
176 | @@ -979,8 +979,8 @@ |
177 | if basis_tree is not None: |
178 | basis_tree.unlock() |
179 | |
180 | - def _deserialise_inventory(self, revision_id, bytes): |
181 | - return inventory.CHKInventory.deserialise(self.chk_bytes, bytes, |
182 | + def _deserialise_inventory(self, revision_id, lines): |
183 | + return inventory.CHKInventory.deserialise(self.chk_bytes, lines, |
184 | (revision_id,)) |
185 | |
186 | def _iter_inventories(self, revision_ids, ordering): |
187 | @@ -992,16 +992,16 @@ |
188 | texts = {} |
189 | for record in stream: |
190 | if record.storage_kind != 'absent': |
191 | - texts[record.key] = record.get_bytes_as('fulltext') |
192 | + texts[record.key] = record.get_bytes_as('lines') |
193 | else: |
194 | texts[record.key] = None |
195 | for key in keys: |
196 | - bytes = texts[key] |
197 | - if bytes is None: |
198 | + lines = texts[key] |
199 | + if lines is None: |
200 | yield (None, key[-1]) |
201 | else: |
202 | yield (inventory.CHKInventory.deserialise( |
203 | - self.chk_bytes, bytes, key), key[-1]) |
204 | + self.chk_bytes, lines, key), key[-1]) |
205 | |
206 | def _get_inventory_xml(self, revision_id): |
207 | """Get serialized inventory as a string.""" |
208 | @@ -1010,7 +1010,7 @@ |
209 | # it allowing _get_inventory_xml to work. Bundles currently use the |
210 | # serializer directly; this also isn't ideal, but there isn't an xml |
211 | # iteration interface offered at all for repositories. |
212 | - return self._serializer.write_inventory_to_string( |
213 | + return self._serializer.write_inventory_to_lines( |
214 | self.get_inventory(revision_id)) |
215 | |
216 | def _find_present_inventory_keys(self, revision_keys): |
217 | @@ -1187,8 +1187,8 @@ |
218 | continue |
219 | else: |
220 | raise errors.NoSuchRevision(self, record.key) |
221 | - bytes = record.get_bytes_as('fulltext') |
222 | - chk_inv = inventory.CHKInventory.deserialise(None, bytes, |
223 | + lines = record.get_bytes_as('lines') |
224 | + chk_inv = inventory.CHKInventory.deserialise(None, lines, |
225 | record.key) |
226 | key = chk_inv.id_to_entry.key() |
227 | if key not in id_roots_set: |
228 | |
229 | === modified file 'breezy/bzr/inventory.py' |
230 | --- breezy/bzr/inventory.py 2019-10-06 11:30:57 +0000 |
231 | +++ breezy/bzr/inventory.py 2020-01-30 16:35:32 +0000 |
232 | @@ -1829,7 +1829,7 @@ |
233 | return result |
234 | |
235 | @classmethod |
236 | - def deserialise(klass, chk_store, bytes, expected_revision_id): |
237 | + def deserialise(klass, chk_store, lines, expected_revision_id): |
238 | """Deserialise a CHKInventory. |
239 | |
240 | :param chk_store: A CHK capable VersionedFiles instance. |
241 | @@ -1838,18 +1838,16 @@ |
242 | for. |
243 | :return: A CHKInventory |
244 | """ |
245 | - lines = bytes.split(b'\n') |
246 | - if lines[-1] != b'': |
247 | - raise AssertionError('bytes to deserialize must end with an eol') |
248 | - lines.pop() |
249 | - if lines[0] != b'chkinventory:': |
250 | + if not lines[-1].endswith(b'\n'): |
251 | + raise ValueError("last line should have trailing eol\n") |
252 | + if lines[0] != b'chkinventory:\n': |
253 | raise ValueError("not a serialised CHKInventory: %r" % bytes) |
254 | info = {} |
255 | allowed_keys = frozenset((b'root_id', b'revision_id', |
256 | b'parent_id_basename_to_file_id', |
257 | b'search_key_name', b'id_to_entry')) |
258 | for line in lines[1:]: |
259 | - key, value = line.split(b': ', 1) |
260 | + key, value = line.rstrip(b'\n').split(b': ', 1) |
261 | if key not in allowed_keys: |
262 | raise errors.BzrError('Unknown key in inventory: %r\n%r' |
263 | % (key, bytes)) |
264 | |
265 | === modified file 'breezy/bzr/serializer.py' |
266 | --- breezy/bzr/serializer.py 2018-11-11 04:08:32 +0000 |
267 | +++ breezy/bzr/serializer.py 2020-01-30 16:35:32 +0000 |
268 | @@ -34,26 +34,35 @@ |
269 | """ |
270 | raise NotImplementedError(self.write_inventory) |
271 | |
272 | - def write_inventory_to_string(self, inv): |
273 | - """Produce a simple string representation of an inventory. |
274 | - |
275 | - Note: this is a *whole inventory* operation, and should only be used |
276 | - sparingly, as it does not scale well with large trees. |
277 | - |
278 | - The requirement for the contents of the string is that it can be passed |
279 | - to read_inventory_from_string and the result is an identical inventory |
280 | - in memory. |
281 | - |
282 | - (All serializers as of 2009-07-29 produce XML, but this is not mandated |
283 | - by the interface.) |
284 | - """ |
285 | - raise NotImplementedError(self.write_inventory_to_string) |
286 | - |
287 | - def read_inventory_from_string(self, string, revision_id=None, |
288 | - entry_cache=None, return_from_cache=False): |
289 | - """Read string into an inventory object. |
290 | - |
291 | - :param string: The serialized inventory to read. |
292 | + def write_inventory_to_chunks(self, inv): |
293 | + """Produce a simple bytestring chunk representation of an inventory. |
294 | + |
295 | + Note: this is a *whole inventory* operation, and should only be used |
296 | + sparingly, as it does not scale well with large trees. |
297 | + |
298 | + The requirement for the contents of the string is that it can be passed |
299 | + to read_inventory_from_lines and the result is an identical inventory |
300 | + in memory. |
301 | + """ |
302 | + raise NotImplementedError(self.write_inventory_to_chunks) |
303 | + |
304 | + def write_inventory_to_lines(self, inv): |
305 | + """Produce a simple lines representation of an inventory. |
306 | + |
307 | + Note: this is a *whole inventory* operation, and should only be used |
308 | + sparingly, as it does not scale well with large trees. |
309 | + |
310 | + The requirement for the contents of the string is that it can be passed |
311 | + to read_inventory_from_lines and the result is an identical inventory |
312 | + in memory. |
313 | + """ |
314 | + raise NotImplementedError(self.write_inventory_to_lines) |
315 | + |
316 | + def read_inventory_from_lines(self, lines, revision_id=None, |
317 | + entry_cache=None, return_from_cache=False): |
318 | + """Read bytestring chunks into an inventory object. |
319 | + |
320 | + :param lines: The serialized inventory to read. |
321 | :param revision_id: If not-None, the expected revision id of the |
322 | inventory. Some serialisers use this to set the results' root |
323 | revision. This should be supplied for deserialising all |
324 | @@ -69,10 +78,10 @@ |
325 | promises not to mutate the returned inventory entries, but it can |
326 | make some operations significantly faster. |
327 | """ |
328 | - raise NotImplementedError(self.read_inventory_from_string) |
329 | + raise NotImplementedError(self.read_inventory_from_lines) |
330 | |
331 | def read_inventory(self, f, revision_id=None): |
332 | - """See read_inventory_from_string.""" |
333 | + """See read_inventory_from_lines.""" |
334 | raise NotImplementedError(self.read_inventory) |
335 | |
336 | def write_revision(self, rev, f): |
337 | |
338 | === modified file 'breezy/bzr/vf_repository.py' |
339 | --- breezy/bzr/vf_repository.py 2020-01-25 14:58:19 +0000 |
340 | +++ breezy/bzr/vf_repository.py 2020-01-30 16:35:32 +0000 |
341 | @@ -854,7 +854,7 @@ |
342 | if kind == 'inventories': |
343 | rev_id = record.key[0] |
344 | inv = self._deserialise_inventory( |
345 | - rev_id, record.get_bytes_as('fulltext')) |
346 | + rev_id, record.get_bytes_as('lines')) |
347 | if last_object is not None: |
348 | delta = inv._make_delta(last_object) |
349 | for old_path, path, file_id, ie in delta: |
350 | @@ -1469,11 +1469,11 @@ |
351 | def _iter_inventories(self, revision_ids, ordering): |
352 | """single-document based inventory iteration.""" |
353 | inv_xmls = self._iter_inventory_xmls(revision_ids, ordering) |
354 | - for text, revision_id in inv_xmls: |
355 | - if text is None: |
356 | + for lines, revision_id in inv_xmls: |
357 | + if lines is None: |
358 | yield None, revision_id |
359 | else: |
360 | - yield self._deserialise_inventory(revision_id, text), revision_id |
361 | + yield self._deserialise_inventory(revision_id, lines), revision_id |
362 | |
363 | def _iter_inventory_xmls(self, revision_ids, ordering): |
364 | if ordering is None: |
365 | @@ -1488,21 +1488,21 @@ |
366 | key_iter = iter(keys) |
367 | next_key = next(key_iter) |
368 | stream = self.inventories.get_record_stream(keys, ordering, True) |
369 | - text_chunks = {} |
370 | + text_lines = {} |
371 | for record in stream: |
372 | if record.storage_kind != 'absent': |
373 | - chunks = record.get_bytes_as('chunked') |
374 | + lines = record.get_bytes_as('lines') |
375 | if order_as_requested: |
376 | - text_chunks[record.key] = chunks |
377 | + text_lines[record.key] = lines |
378 | else: |
379 | - yield b''.join(chunks), record.key[-1] |
380 | + yield lines, record.key[-1] |
381 | else: |
382 | yield None, record.key[-1] |
383 | if order_as_requested: |
384 | # Yield as many results as we can while preserving order. |
385 | - while next_key in text_chunks: |
386 | - chunks = text_chunks.pop(next_key) |
387 | - yield b''.join(chunks), next_key[-1] |
388 | + while next_key in text_lines: |
389 | + lines = text_lines.pop(next_key) |
390 | + yield lines, next_key[-1] |
391 | try: |
392 | next_key = next(key_iter) |
393 | except StopIteration: |
394 | @@ -1517,9 +1517,9 @@ |
395 | :param revision_id: The expected revision id of the inventory. |
396 | :param xml: A serialised inventory. |
397 | """ |
398 | - result = self._serializer.read_inventory_from_string(xml, revision_id, |
399 | - entry_cache=self._inventory_entry_cache, |
400 | - return_from_cache=self._safe_to_return_from_cache) |
401 | + result = self._serializer.read_inventory_from_lines( |
402 | + xml, revision_id, entry_cache=self._inventory_entry_cache, |
403 | + return_from_cache=self._safe_to_return_from_cache) |
404 | if result.revision_id != revision_id: |
405 | raise AssertionError('revision id mismatch %s != %s' % ( |
406 | result.revision_id, revision_id)) |
407 | @@ -1532,10 +1532,10 @@ |
408 | """Get serialized inventory as a string.""" |
409 | with self.lock_read(): |
410 | texts = self._iter_inventory_xmls([revision_id], 'unordered') |
411 | - text, revision_id = next(texts) |
412 | - if text is None: |
413 | + lines, revision_id = next(texts) |
414 | + if lines is None: |
415 | raise errors.NoSuchRevision(self, revision_id) |
416 | - return text |
417 | + return lines |
418 | |
419 | def revision_tree(self, revision_id): |
420 | """Return Tree for a revision on this branch. |
421 | @@ -1963,9 +1963,9 @@ |
422 | for record in substream: |
423 | # It's not a delta, so it must be a fulltext in the source |
424 | # serializer's format. |
425 | - bytes = record.get_bytes_as('fulltext') |
426 | + lines = record.get_bytes_as('lines') |
427 | revision_id = record.key[0] |
428 | - inv = serializer.read_inventory_from_string(bytes, revision_id) |
429 | + inv = serializer.read_inventory_from_lines(lines, revision_id) |
430 | parents = [key[0] for key in record.parents] |
431 | self.target_repo.add_inventory(revision_id, inv, parents) |
432 | # No need to keep holding this full inv in memory when the rest of |
433 | |
434 | === modified file 'breezy/bzr/workingtree.py' |
435 | --- breezy/bzr/workingtree.py 2020-01-19 03:22:04 +0000 |
436 | +++ breezy/bzr/workingtree.py 2020-01-30 16:35:32 +0000 |
437 | @@ -303,7 +303,7 @@ |
438 | def _write_basis_inventory(self, xml): |
439 | """Write the basis inventory XML to the basis-inventory file""" |
440 | path = self._basis_inventory_name() |
441 | - sio = BytesIO(xml) |
442 | + sio = BytesIO(b''.join(xml)) |
443 | self._transport.put_file(path, sio, |
444 | mode=self.controldir._get_file_mode()) |
445 | |
446 | @@ -548,14 +548,14 @@ |
447 | # revision_id is set. We must check for this full string, because a |
448 | # root node id can legitimately look like 'revision_id' but cannot |
449 | # contain a '"'. |
450 | - xml = self.branch.repository._get_inventory_xml(new_revision) |
451 | - firstline = xml.split(b'\n', 1)[0] |
452 | + lines = self.branch.repository._get_inventory_xml(new_revision) |
453 | + firstline = lines[0] |
454 | if (b'revision_id="' not in firstline |
455 | or b'format="7"' not in firstline): |
456 | - inv = self.branch.repository._serializer.read_inventory_from_string( |
457 | - xml, new_revision) |
458 | - xml = self._create_basis_xml_from_inventory(new_revision, inv) |
459 | - self._write_basis_inventory(xml) |
460 | + inv = self.branch.repository._serializer.read_inventory_from_lines( |
461 | + lines, new_revision) |
462 | + lines = self._create_basis_xml_from_inventory(new_revision, inv) |
463 | + self._write_basis_inventory(lines) |
464 | except (errors.NoSuchRevision, errors.RevisionNotPresent): |
465 | pass |
466 | |
467 | @@ -565,7 +565,7 @@ |
468 | def _create_basis_xml_from_inventory(self, revision_id, inventory): |
469 | """Create the text that will be saved in basis-inventory""" |
470 | inventory.revision_id = revision_id |
471 | - return xml7.serializer_v7.write_inventory_to_string(inventory) |
472 | + return xml7.serializer_v7.write_inventory_to_lines(inventory) |
473 | |
474 | def set_conflicts(self, conflicts): |
475 | with self.lock_tree_write(): |
476 | @@ -641,7 +641,7 @@ |
477 | def read_basis_inventory(self): |
478 | """Read the cached basis inventory.""" |
479 | path = self._basis_inventory_name() |
480 | - return self._transport.get_bytes(path) |
481 | + return osutils.split_lines(self._transport.get_bytes(path)) |
482 | |
483 | def read_working_inventory(self): |
484 | """Read the working inventory. |
485 | @@ -801,12 +801,12 @@ |
486 | """See WorkingTree.revision_id.""" |
487 | if revision_id == self.last_revision(): |
488 | try: |
489 | - xml = self.read_basis_inventory() |
490 | + xml_lines = self.read_basis_inventory() |
491 | except errors.NoSuchFile: |
492 | pass |
493 | else: |
494 | try: |
495 | - inv = xml7.serializer_v7.read_inventory_from_string(xml) |
496 | + inv = xml7.serializer_v7.read_inventory_from_lines(xml_lines) |
497 | # dont use the repository revision_tree api because we want |
498 | # to supply the inventory. |
499 | if inv.revision_id == revision_id: |
500 | |
501 | === modified file 'breezy/bzr/xml8.py' |
502 | --- breezy/bzr/xml8.py 2018-11-16 11:37:47 +0000 |
503 | +++ breezy/bzr/xml8.py 2020-01-30 16:35:32 +0000 |
504 | @@ -134,15 +134,8 @@ |
505 | """Return a list of lines with the encoded inventory.""" |
506 | return self.write_inventory(inv, None) |
507 | |
508 | - def write_inventory_to_string(self, inv, working=False): |
509 | - """Just call write_inventory with a BytesIO and return the value. |
510 | - |
511 | - :param working: If True skip history data - text_sha1, text_size, |
512 | - reference_revision, symlink_target. |
513 | - """ |
514 | - sio = BytesIO() |
515 | - self.write_inventory(inv, sio, working) |
516 | - return sio.getvalue() |
517 | + def write_inventory_to_chunks(self, inv): |
518 | + return self.write_inventory(inv, None) |
519 | |
520 | def write_inventory(self, inv, f, working=False): |
521 | """Write inventory to a file. |
522 | |
523 | === modified file 'breezy/bzr/xml_serializer.py' |
524 | --- breezy/bzr/xml_serializer.py 2019-02-14 05:21:21 +0000 |
525 | +++ breezy/bzr/xml_serializer.py 2020-01-30 16:35:32 +0000 |
526 | @@ -28,7 +28,7 @@ |
527 | |
528 | try: |
529 | import xml.etree.cElementTree as elementtree |
530 | - ParseError = getattr(elementtree, "ParseError", SyntaxError) |
531 | + from xml.etree.ElementTree import ParseError |
532 | except ImportError: |
533 | # Fall back to pure python implementation if C extension is unavailable |
534 | import xml.etree.ElementTree as elementtree |
535 | @@ -37,9 +37,11 @@ |
536 | except ImportError: |
537 | from xml.parsers.expat import ExpatError as ParseError |
538 | |
539 | -(ElementTree, SubElement, Element, fromstring, tostring) = ( |
540 | +(ElementTree, SubElement, Element, fromstringlist, tostringlist, tostring, |
541 | + fromstring) = ( |
542 | elementtree.ElementTree, elementtree.SubElement, elementtree.Element, |
543 | - elementtree.fromstring, elementtree.tostring) |
544 | + elementtree.fromstringlist, elementtree.tostringlist, elementtree.tostring, |
545 | + elementtree.fromstring) |
546 | |
547 | |
548 | from .. import ( |
549 | @@ -59,11 +61,11 @@ |
550 | |
551 | squashes_xml_invalid_characters = True |
552 | |
553 | - def read_inventory_from_string(self, xml_string, revision_id=None, |
554 | - entry_cache=None, return_from_cache=False): |
555 | + def read_inventory_from_lines(self, lines, revision_id=None, |
556 | + entry_cache=None, return_from_cache=False): |
557 | """Read xml_string into an inventory object. |
558 | |
559 | - :param xml_string: The xml to read. |
560 | + :param chunks: The xml to read. |
561 | :param revision_id: If not-None, the expected revision id of the |
562 | inventory. Some serialisers use this to set the results' root |
563 | revision. This should be supplied for deserialising all |
564 | @@ -80,7 +82,7 @@ |
565 | make some operations significantly faster. |
566 | """ |
567 | try: |
568 | - return self._unpack_inventory(fromstring(xml_string), revision_id, |
569 | + return self._unpack_inventory(fromstringlist(lines), revision_id, |
570 | entry_cache=entry_cache, |
571 | return_from_cache=return_from_cache) |
572 | except ParseError as e: |
573 | |
574 | === modified file 'breezy/plugins/weave_fmt/bzrdir.py' |
575 | --- breezy/plugins/weave_fmt/bzrdir.py 2019-10-19 23:18:56 +0000 |
576 | +++ breezy/plugins/weave_fmt/bzrdir.py 2020-01-30 16:35:32 +0000 |
577 | @@ -18,6 +18,8 @@ |
578 | |
579 | from __future__ import absolute_import |
580 | |
581 | +from io import BytesIO |
582 | + |
583 | from ...bzr.bzrdir import ( |
584 | BzrDir, |
585 | BzrDirFormat, |
586 | @@ -311,9 +313,9 @@ |
587 | def _convert_working_inv(self): |
588 | inv = xml4.serializer_v4.read_inventory( |
589 | self.branch._transport.get('inventory')) |
590 | - new_inv_xml = xml5.serializer_v5.write_inventory_to_string( |
591 | - inv, working=True) |
592 | - self.branch._transport.put_bytes('inventory', new_inv_xml, |
593 | + f = BytesIO() |
594 | + xml5.serializer_v5.write_inventory(inv, f, working=True) |
595 | + self.branch._transport.put_bytes('inventory', f.getvalue(), |
596 | mode=self.controldir._get_file_mode()) |
597 | |
598 | def _write_all_weaves(self): |
599 | @@ -382,15 +384,14 @@ |
600 | |
601 | def _load_old_inventory(self, rev_id): |
602 | with self.branch.repository.inventory_store.get(rev_id) as f: |
603 | - old_inv_xml = f.read() |
604 | - inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml) |
605 | + inv = xml4.serializer_v4.read_inventory(f) |
606 | inv.revision_id = rev_id |
607 | rev = self.revisions[rev_id] |
608 | return inv |
609 | |
610 | def _load_updated_inventory(self, rev_id): |
611 | - inv_xml = self.inv_weave.get_text(rev_id) |
612 | - inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id) |
613 | + inv_xml = self.inv_weave.get_lines(rev_id) |
614 | + inv = xml5.serializer_v5.read_inventory_from_lines(inv_xml, rev_id) |
615 | return inv |
616 | |
617 | def _convert_one_rev(self, rev_id): |
618 | @@ -404,11 +405,11 @@ |
619 | self.converted_revs.add(rev_id) |
620 | |
621 | def _store_new_inv(self, rev, inv, present_parents): |
622 | - new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv) |
623 | - new_inv_sha1 = osutils.sha_string(new_inv_xml) |
624 | + new_inv_xml = xml5.serializer_v5.write_inventory_to_lines(inv) |
625 | + new_inv_sha1 = osutils.sha_strings(new_inv_xml) |
626 | self.inv_weave.add_lines(rev.revision_id, |
627 | present_parents, |
628 | - new_inv_xml.splitlines(True)) |
629 | + new_inv_xml) |
630 | rev.inventory_sha1 = new_inv_sha1 |
631 | |
632 | def _convert_revision_contents(self, rev, inv, present_parents): |
633 | |
634 | === modified file 'breezy/tests/per_pack_repository.py' |
635 | --- breezy/tests/per_pack_repository.py 2019-12-23 03:04:00 +0000 |
636 | +++ breezy/tests/per_pack_repository.py 2020-01-30 16:35:32 +0000 |
637 | @@ -786,8 +786,8 @@ |
638 | same_repo.resume_write_group(wg_tokens) |
639 | self.assertEqual([key], list(same_repo.chk_bytes.keys())) |
640 | self.assertEqual( |
641 | - text, next(same_repo.chk_bytes.get_record_stream([key], |
642 | - 'unordered', True)).get_bytes_as('fulltext')) |
643 | + text, next(same_repo.chk_bytes.get_record_stream( |
644 | + [key], 'unordered', True)).get_bytes_as('fulltext')) |
645 | same_repo.abort_write_group() |
646 | self.assertEqual([], list(same_repo.chk_bytes.keys())) |
647 | |
648 | |
649 | === modified file 'breezy/tests/per_repository_reference/test_fetch.py' |
650 | --- breezy/tests/per_repository_reference/test_fetch.py 2018-11-11 04:08:32 +0000 |
651 | +++ breezy/tests/per_repository_reference/test_fetch.py 2020-01-30 16:35:32 +0000 |
652 | @@ -74,8 +74,8 @@ |
653 | self.assertEqual(b'C-id', final_b.last_revision()) |
654 | text_keys = [(b'a-id', b'A-id'), (b'a-id', b'B-id'), |
655 | (b'a-id', b'C-id')] |
656 | - stream = final_b.repository.texts.get_record_stream(text_keys, |
657 | - 'unordered', True) |
658 | + stream = final_b.repository.texts.get_record_stream( |
659 | + text_keys, 'unordered', True) |
660 | records = sorted([(r.key, r.get_bytes_as('fulltext')) for r in stream]) |
661 | self.assertEqual([ |
662 | ((b'a-id', b'A-id'), b''.join(content[:-2])), |
663 | |
664 | === modified file 'breezy/tests/per_workingtree/test_basis_inventory.py' |
665 | --- breezy/tests/per_workingtree/test_basis_inventory.py 2018-11-11 04:08:32 +0000 |
666 | +++ breezy/tests/per_workingtree/test_basis_inventory.py 2020-01-30 16:35:32 +0000 |
667 | @@ -58,9 +58,9 @@ |
668 | |
669 | self.assertTrue(t._transport.has('basis-inventory-cache')) |
670 | |
671 | - basis_inv_txt = t.read_basis_inventory() |
672 | - basis_inv = breezy.bzr.xml7.serializer_v7.read_inventory_from_string( |
673 | - basis_inv_txt) |
674 | + basis_inv_lines = t.read_basis_inventory() |
675 | + basis_inv = breezy.bzr.xml7.serializer_v7.read_inventory_from_lines( |
676 | + basis_inv_lines) |
677 | self.assertEqual(r2, basis_inv.revision_id) |
678 | store_inv = b.repository.get_inventory(r2) |
679 | |
680 | |
681 | === modified file 'breezy/tests/test_bundle.py' |
682 | --- breezy/tests/test_bundle.py 2020-01-19 13:47:29 +0000 |
683 | +++ breezy/tests/test_bundle.py 2020-01-30 16:35:32 +0000 |
684 | @@ -1036,7 +1036,7 @@ |
685 | bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0]) |
686 | repo = self.make_repository('repo', format='dirstate-with-subtree') |
687 | bundle.install_revisions(repo) |
688 | - inv_text = repo._get_inventory_xml(b'rev2') |
689 | + inv_text = b''.join(repo._get_inventory_xml(b'rev2')) |
690 | self.assertNotContainsRe(inv_text, b'format="5"') |
691 | self.assertContainsRe(inv_text, b'format="7"') |
692 | |
693 | @@ -1063,7 +1063,7 @@ |
694 | def test_inv_hash_across_serializers(self): |
695 | repo = self.make_repo_with_installed_revisions() |
696 | recorded_inv_sha1 = repo.get_revision(b'rev2').inventory_sha1 |
697 | - xml = repo._get_inventory_xml(b'rev2') |
698 | + xml = b''.join(repo._get_inventory_xml(b'rev2')) |
699 | self.assertEqual(osutils.sha_string(xml), recorded_inv_sha1) |
700 | |
701 | def test_across_models_incompatible(self): |
702 | |
703 | === modified file 'breezy/tests/test_inv.py' |
704 | --- breezy/tests/test_inv.py 2019-05-29 03:22:34 +0000 |
705 | +++ breezy/tests/test_inv.py 2020-01-30 16:35:32 +0000 |
706 | @@ -861,8 +861,8 @@ |
707 | inv.root.revision = b"rootrev" |
708 | chk_bytes = self.get_chk_bytes() |
709 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
710 | - bytes = b''.join(chk_inv.to_lines()) |
711 | - new_inv = CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
712 | + lines = chk_inv.to_lines() |
713 | + new_inv = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
714 | self.assertEqual(b"revid", new_inv.revision_id) |
715 | self.assertEqual("directory", new_inv.root.kind) |
716 | self.assertEqual(inv.root.file_id, new_inv.root.file_id) |
717 | @@ -877,9 +877,9 @@ |
718 | inv.root.revision = b"rootrev" |
719 | chk_bytes = self.get_chk_bytes() |
720 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
721 | - bytes = b''.join(chk_inv.to_lines()) |
722 | + lines = chk_inv.to_lines() |
723 | self.assertRaises(ValueError, CHKInventory.deserialise, chk_bytes, |
724 | - bytes, (b"revid2",)) |
725 | + lines, (b"revid2",)) |
726 | |
727 | def test_captures_rev_root_byid(self): |
728 | inv = Inventory() |
729 | @@ -896,7 +896,7 @@ |
730 | b'id_to_entry: sha1:debfe920f1f10e7929260f0534ac9a24d7aabbb4\n', |
731 | ], lines) |
732 | chk_inv = CHKInventory.deserialise( |
733 | - chk_bytes, b''.join(lines), (b'foo',)) |
734 | + chk_bytes, lines, (b'foo',)) |
735 | self.assertEqual(b'plain', chk_inv._search_key_name) |
736 | |
737 | def test_captures_parent_id_basename_index(self): |
738 | @@ -914,7 +914,7 @@ |
739 | b'id_to_entry: sha1:debfe920f1f10e7929260f0534ac9a24d7aabbb4\n', |
740 | ], lines) |
741 | chk_inv = CHKInventory.deserialise( |
742 | - chk_bytes, b''.join(lines), (b'foo',)) |
743 | + chk_bytes, lines, (b'foo',)) |
744 | self.assertEqual(b'plain', chk_inv._search_key_name) |
745 | |
746 | def test_captures_search_key_name(self): |
747 | @@ -934,7 +934,7 @@ |
748 | b'id_to_entry: sha1:debfe920f1f10e7929260f0534ac9a24d7aabbb4\n', |
749 | ], lines) |
750 | chk_inv = CHKInventory.deserialise( |
751 | - chk_bytes, b''.join(lines), (b'foo',)) |
752 | + chk_bytes, lines, (b'foo',)) |
753 | self.assertEqual(b'hash-16-way', chk_inv._search_key_name) |
754 | |
755 | def test_directory_children_on_demand(self): |
756 | @@ -948,8 +948,8 @@ |
757 | inv.get_entry(b"fileid").text_size = 1 |
758 | chk_bytes = self.get_chk_bytes() |
759 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
760 | - bytes = b''.join(chk_inv.to_lines()) |
761 | - new_inv = CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
762 | + lines = chk_inv.to_lines() |
763 | + new_inv = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
764 | root_entry = new_inv.get_entry(inv.root.file_id) |
765 | self.assertEqual(None, root_entry._children) |
766 | self.assertEqual({'file'}, set(root_entry.children)) |
767 | @@ -990,8 +990,8 @@ |
768 | inv.get_entry(b"fileid").text_size = 1 |
769 | chk_bytes = self.get_chk_bytes() |
770 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
771 | - bytes = b''.join(chk_inv.to_lines()) |
772 | - new_inv = CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
773 | + lines = chk_inv.to_lines() |
774 | + new_inv = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
775 | fileids = sorted(new_inv.iter_all_ids()) |
776 | self.assertEqual([inv.root.file_id, b"fileid"], fileids) |
777 | |
778 | @@ -1019,8 +1019,8 @@ |
779 | inv.get_entry(b"fileid").text_size = 1 |
780 | chk_bytes = self.get_chk_bytes() |
781 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
782 | - data = b''.join(chk_inv.to_lines()) |
783 | - new_inv = CHKInventory.deserialise(chk_bytes, data, (b"revid",)) |
784 | + lines = chk_inv.to_lines() |
785 | + new_inv = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
786 | root_entry = new_inv.get_entry(inv.root.file_id) |
787 | file_entry = new_inv.get_entry(b"fileid") |
788 | self.assertEqual("directory", root_entry.kind) |
789 | @@ -1075,8 +1075,8 @@ |
790 | inv.get_entry(b"dirid").revision = b"filerev" |
791 | chk_bytes = self.get_chk_bytes() |
792 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
793 | - bytes = b''.join(chk_inv.to_lines()) |
794 | - new_inv = CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
795 | + lines = chk_inv.to_lines() |
796 | + new_inv = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
797 | self.assertEqual('', new_inv.id2path(inv.root.file_id)) |
798 | self.assertEqual('dir', new_inv.id2path(b'dirid')) |
799 | self.assertEqual('dir/file', new_inv.id2path(b'fileid')) |
800 | @@ -1096,8 +1096,8 @@ |
801 | inv.get_entry(b"dirid").revision = b"filerev" |
802 | chk_bytes = self.get_chk_bytes() |
803 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
804 | - bytes = b''.join(chk_inv.to_lines()) |
805 | - new_inv = CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
806 | + lines = chk_inv.to_lines() |
807 | + new_inv = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
808 | self.assertEqual(inv.root.file_id, new_inv.path2id('')) |
809 | self.assertEqual(b'dirid', new_inv.path2id('dir')) |
810 | self.assertEqual(b'fileid', new_inv.path2id('dir/file')) |
811 | @@ -1191,11 +1191,11 @@ |
812 | # get fresh objects. |
813 | chk_bytes = self.get_chk_bytes() |
814 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
815 | - bytes = b''.join(chk_inv.to_lines()) |
816 | - inv_1 = CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
817 | + lines = chk_inv.to_lines() |
818 | + inv_1 = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
819 | chk_inv2 = CHKInventory.from_inventory(chk_bytes, inv2) |
820 | - bytes = b''.join(chk_inv2.to_lines()) |
821 | - inv_2 = CHKInventory.deserialise(chk_bytes, bytes, (b"revid2",)) |
822 | + lines = chk_inv2.to_lines() |
823 | + inv_2 = CHKInventory.deserialise(chk_bytes, lines, (b"revid2",)) |
824 | self.assertEqual([(b'fileid', (u'file', u'file'), True, (True, True), |
825 | (b'TREE_ROOT', b'TREE_ROOT'), (u'file', |
826 | u'file'), ('file', 'file'), |
827 | @@ -1214,8 +1214,8 @@ |
828 | # get fresh objects. |
829 | chk_bytes = self.get_chk_bytes() |
830 | tmp_inv = CHKInventory.from_inventory(chk_bytes, inv) |
831 | - bytes = b''.join(tmp_inv.to_lines()) |
832 | - chk_inv = CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
833 | + lines = tmp_inv.to_lines() |
834 | + chk_inv = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
835 | self.assertIsInstance( |
836 | chk_inv.parent_id_basename_to_file_id, chk_map.CHKMap) |
837 | self.assertEqual( |
838 | @@ -1345,8 +1345,8 @@ |
839 | inv.get_entry(b"childid").text_size = 0 |
840 | chk_bytes = self.get_chk_bytes() |
841 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
842 | - bytes = b''.join(chk_inv.to_lines()) |
843 | - return CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
844 | + lines = chk_inv.to_lines() |
845 | + return CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
846 | |
847 | def test__preload_handles_utf8(self): |
848 | new_inv = self.make_basic_utf8_inventory() |
849 | @@ -1381,8 +1381,8 @@ |
850 | inv.get_entry(b"childid").text_size = 1 |
851 | chk_bytes = self.get_chk_bytes() |
852 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv) |
853 | - bytes = b''.join(chk_inv.to_lines()) |
854 | - new_inv = CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
855 | + lines = chk_inv.to_lines() |
856 | + new_inv = CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
857 | self.assertEqual({}, new_inv._fileid_to_entry_cache) |
858 | self.assertFalse(new_inv._fully_cached) |
859 | new_inv._preload_cache() |
860 | @@ -1485,8 +1485,8 @@ |
861 | chk_inv = CHKInventory.from_inventory(chk_bytes, inv, |
862 | maximum_size=100, |
863 | search_key_name=b'hash-255-way') |
864 | - bytes = b''.join(chk_inv.to_lines()) |
865 | - return CHKInventory.deserialise(chk_bytes, bytes, (b"revid",)) |
866 | + lines = chk_inv.to_lines() |
867 | + return CHKInventory.deserialise(chk_bytes, lines, (b"revid",)) |
868 | |
869 | def assert_Getitems(self, expected_fileids, inv, file_ids): |
870 | self.assertEqual(sorted(expected_fileids), |
871 | |
872 | === modified file 'breezy/tests/test_remote.py' |
873 | --- breezy/tests/test_remote.py 2020-01-19 14:49:03 +0000 |
874 | +++ breezy/tests/test_remote.py 2020-01-30 16:35:32 +0000 |
875 | @@ -3536,9 +3536,9 @@ |
876 | |
877 | def inventories_substream(): |
878 | # An empty inventory fulltext. This will be streamed normally. |
879 | - text = fmt._serializer.write_inventory_to_string(inv) |
880 | - yield versionedfile.FulltextContentFactory( |
881 | - (b'rev1',), (), None, text) |
882 | + chunks = fmt._serializer.write_inventory_to_lines(inv) |
883 | + yield versionedfile.ChunkedContentFactory( |
884 | + (b'rev1',), (), None, chunks, chunks_are_lines=True) |
885 | |
886 | def inventory_delta_substream(): |
887 | # An inventory delta. This can't be streamed via this verb, so it |
888 | |
889 | === modified file 'breezy/tests/test_repository.py' |
890 | --- breezy/tests/test_repository.py 2018-11-16 18:40:46 +0000 |
891 | +++ breezy/tests/test_repository.py 2020-01-30 16:35:32 +0000 |
892 | @@ -329,7 +329,7 @@ |
893 | repo = self.make_repository( |
894 | '.', format=controldir.format_registry.get('knit')()) |
895 | inv_xml = b'<inventory format="5">\n</inventory>\n' |
896 | - inv = repo._deserialise_inventory(b'test-rev-id', inv_xml) |
897 | + inv = repo._deserialise_inventory(b'test-rev-id', [inv_xml]) |
898 | self.assertEqual(b'test-rev-id', inv.root.revision) |
899 | |
900 | def test_deserialise_uses_global_revision_id(self): |
901 | @@ -342,8 +342,8 @@ |
902 | # raise an error, rather than silently using one revision_id over the |
903 | # other. |
904 | self.assertRaises(AssertionError, repo._deserialise_inventory, |
905 | - b'test-rev-id', inv_xml) |
906 | - inv = repo._deserialise_inventory(b'other-rev-id', inv_xml) |
907 | + b'test-rev-id', [inv_xml]) |
908 | + inv = repo._deserialise_inventory(b'other-rev-id', [inv_xml]) |
909 | self.assertEqual(b'other-rev-id', inv.root.revision) |
910 | |
911 | def test_supports_external_lookups(self): |
912 | |
913 | === modified file 'breezy/tests/test_xml.py' |
914 | --- breezy/tests/test_xml.py 2019-02-14 05:21:21 +0000 |
915 | +++ breezy/tests/test_xml.py 2020-01-30 16:35:32 +0000 |
916 | @@ -236,8 +236,8 @@ |
917 | |
918 | def test_unpack_basis_inventory_5(self): |
919 | """Unpack canned new-style inventory""" |
920 | - inp = BytesIO(_basis_inv_v5) |
921 | - inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp) |
922 | + inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines( |
923 | + breezy.osutils.split_lines(_basis_inv_v5)) |
924 | eq = self.assertEqual |
925 | eq(len(inv), 4) |
926 | eq(inv.revision_id, |
927 | @@ -249,8 +249,8 @@ |
928 | eq(inv.get_entry(ie.parent_id).kind, 'directory') |
929 | |
930 | def test_unpack_inventory_5a(self): |
931 | - inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( |
932 | - _inventory_v5a, revision_id=b'test-rev-id') |
933 | + inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines( |
934 | + breezy.osutils.split_lines(_inventory_v5a), revision_id=b'test-rev-id') |
935 | self.assertEqual(b'test-rev-id', inv.root.revision) |
936 | |
937 | def test_unpack_inventory_5a_cache_and_copy(self): |
938 | @@ -258,8 +258,8 @@ |
939 | # But the returned objects should be copies if return_from_cache is |
940 | # False |
941 | entry_cache = fifo_cache.FIFOCache() |
942 | - inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( |
943 | - _inventory_v5a, revision_id=b'test-rev-id', |
944 | + inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines( |
945 | + breezy.osutils.split_lines(_inventory_v5a), revision_id=b'test-rev-id', |
946 | entry_cache=entry_cache, return_from_cache=False) |
947 | for entry in inv.iter_just_entries(): |
948 | key = (entry.file_id, entry.revision) |
949 | @@ -274,8 +274,8 @@ |
950 | # The returned objects should be exact if return_from_cache is |
951 | # True |
952 | entry_cache = fifo_cache.FIFOCache() |
953 | - inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( |
954 | - _inventory_v5a, revision_id=b'test-rev-id', |
955 | + inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines( |
956 | + breezy.osutils.split_lines(_inventory_v5a), revision_id=b'test-rev-id', |
957 | entry_cache=entry_cache, return_from_cache=True) |
958 | for entry in inv.iter_just_entries(): |
959 | key = (entry.file_id, entry.revision) |
960 | @@ -286,18 +286,18 @@ |
961 | self.assertIs(entry, entry_cache[key]) |
962 | |
963 | def test_unpack_inventory_5b(self): |
964 | - inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( |
965 | - _inventory_v5b, revision_id=b'test-rev-id') |
966 | + inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines( |
967 | + breezy.osutils.split_lines(_inventory_v5b), revision_id=b'test-rev-id') |
968 | self.assertEqual(b'a-rev-id', inv.root.revision) |
969 | |
970 | def test_repack_inventory_5(self): |
971 | - inp = BytesIO(_committed_inv_v5) |
972 | - inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp) |
973 | + inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines( |
974 | + breezy.osutils.split_lines(_committed_inv_v5)) |
975 | outp = BytesIO() |
976 | breezy.bzr.xml5.serializer_v5.write_inventory(inv, outp) |
977 | self.assertEqualDiff(_expected_inv_v5, outp.getvalue()) |
978 | - inv2 = breezy.bzr.xml5.serializer_v5.read_inventory( |
979 | - BytesIO(outp.getvalue())) |
980 | + inv2 = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines( |
981 | + breezy.osutils.split_lines(outp.getvalue())) |
982 | self.assertEqual(inv, inv2) |
983 | |
984 | def assertRoundTrips(self, xml_string): |
985 | @@ -377,22 +377,18 @@ |
986 | inv = self.get_sample_inventory() |
987 | inv.add(inventory.TreeReference(b'nested-id', 'nested', b'tree-root-321', |
988 | b'rev_outer', b'rev_inner')) |
989 | - txt = xml7.serializer_v7.write_inventory_to_string(inv) |
990 | lines = xml7.serializer_v7.write_inventory_to_lines(inv) |
991 | - self.assertEqual(breezy.osutils.split_lines(txt), lines) |
992 | - self.assertEqualDiff(_expected_inv_v7, txt) |
993 | - inv2 = xml7.serializer_v7.read_inventory_from_string(txt) |
994 | + self.assertEqualDiff(_expected_inv_v7, b''.join(lines)) |
995 | + inv2 = xml7.serializer_v7.read_inventory_from_lines(lines) |
996 | self.assertEqual(5, len(inv2)) |
997 | for path, ie in inv.iter_entries(): |
998 | self.assertEqual(ie, inv2.get_entry(ie.file_id)) |
999 | |
1000 | def test_roundtrip_inventory_v6(self): |
1001 | inv = self.get_sample_inventory() |
1002 | - txt = xml6.serializer_v6.write_inventory_to_string(inv) |
1003 | lines = xml6.serializer_v6.write_inventory_to_lines(inv) |
1004 | - self.assertEqual(breezy.osutils.split_lines(txt), lines) |
1005 | - self.assertEqualDiff(_expected_inv_v6, txt) |
1006 | - inv2 = xml6.serializer_v6.read_inventory_from_string(txt) |
1007 | + self.assertEqualDiff(_expected_inv_v6, b''.join(lines)) |
1008 | + inv2 = xml6.serializer_v6.read_inventory_from_lines(lines) |
1009 | self.assertEqual(4, len(inv2)) |
1010 | for path, ie in inv.iter_entries(): |
1011 | self.assertEqual(ie, inv2.get_entry(ie.file_id)) |
1012 | @@ -402,9 +398,11 @@ |
1013 | s_v6 = breezy.bzr.xml6.serializer_v6 |
1014 | s_v7 = xml7.serializer_v7 |
1015 | self.assertRaises(errors.UnexpectedInventoryFormat, |
1016 | - s_v7.read_inventory_from_string, _expected_inv_v5) |
1017 | + s_v7.read_inventory_from_lines, |
1018 | + breezy.osutils.split_lines(_expected_inv_v5)) |
1019 | self.assertRaises(errors.UnexpectedInventoryFormat, |
1020 | - s_v6.read_inventory_from_string, _expected_inv_v7) |
1021 | + s_v6.read_inventory_from_lines, |
1022 | + breezy.osutils.split_lines(_expected_inv_v7)) |
1023 | |
1024 | def test_tree_reference(self): |
1025 | s_v5 = breezy.bzr.xml5.serializer_v5 |
1026 | @@ -415,13 +413,11 @@ |
1027 | inv.add(inventory.TreeReference(b'nested-id', 'nested', b'tree-root-321', |
1028 | b'rev-outer', b'rev-inner')) |
1029 | self.assertRaises(errors.UnsupportedInventoryKind, |
1030 | - s_v5.write_inventory_to_string, inv) |
1031 | + s_v5.write_inventory_to_lines, inv) |
1032 | self.assertRaises(errors.UnsupportedInventoryKind, |
1033 | - s_v6.write_inventory_to_string, inv) |
1034 | - txt = s_v7.write_inventory_to_string(inv) |
1035 | - lines = s_v7.write_inventory_to_lines(inv) |
1036 | - self.assertEqual(breezy.osutils.split_lines(txt), lines) |
1037 | - inv2 = s_v7.read_inventory_from_string(txt) |
1038 | + s_v6.write_inventory_to_lines, inv) |
1039 | + lines = s_v7.write_inventory_to_chunks(inv) |
1040 | + inv2 = s_v7.read_inventory_from_lines(lines) |
1041 | self.assertEqual(b'tree-root-321', |
1042 | inv2.get_entry(b'nested-id').parent_id) |
1043 | self.assertEqual(b'rev-outer', inv2.get_entry(b'nested-id').revision) |
1044 | @@ -430,18 +426,16 @@ |
1045 | |
1046 | def test_roundtrip_inventory_v8(self): |
1047 | inv = self.get_sample_inventory() |
1048 | - txt = xml8.serializer_v8.write_inventory_to_string(inv) |
1049 | - inv2 = xml8.serializer_v8.read_inventory_from_string(txt) |
1050 | + lines = xml8.serializer_v8.write_inventory_to_lines(inv) |
1051 | + inv2 = xml8.serializer_v8.read_inventory_from_lines(lines) |
1052 | self.assertEqual(4, len(inv2)) |
1053 | for path, ie in inv.iter_entries(): |
1054 | self.assertEqual(ie, inv2.get_entry(ie.file_id)) |
1055 | |
1056 | def test_inventory_text_v8(self): |
1057 | inv = self.get_sample_inventory() |
1058 | - txt = xml8.serializer_v8.write_inventory_to_string(inv) |
1059 | lines = xml8.serializer_v8.write_inventory_to_lines(inv) |
1060 | - self.assertEqual(breezy.osutils.split_lines(txt), lines) |
1061 | - self.assertEqualDiff(_expected_inv_v8, txt) |
1062 | + self.assertEqualDiff(_expected_inv_v8, b''.join(lines)) |
1063 | |
1064 | def test_revision_text_v6(self): |
1065 | """Pack revision to XML v6""" |
1066 | @@ -480,7 +474,7 @@ |
1067 | self.assertIsInstance(rev.message, text_type) |
1068 | |
1069 | # ie.revision should either be None or a utf-8 revision id |
1070 | - inv = s_v5.read_inventory_from_string(_inventory_utf8_v5) |
1071 | + inv = s_v5.read_inventory_from_lines(breezy.osutils.split_lines(_inventory_utf8_v5)) |
1072 | rev_id_1 = u'erik@b\xe5gfors-01'.encode('utf8') |
1073 | rev_id_2 = u'erik@b\xe5gfors-02'.encode('utf8') |
1074 | fid_root = u'TRE\xe9_ROOT'.encode('utf8') |
1075 | @@ -515,7 +509,7 @@ |
1076 | s_v5 = breezy.bzr.xml5.serializer_v5 |
1077 | e = self.assertRaises( |
1078 | errors.UnexpectedInventoryFormat, |
1079 | - s_v5.read_inventory_from_string, b"<Notquitexml") |
1080 | + s_v5.read_inventory_from_lines, [b"<Notquitexml"]) |
1081 | self.assertEqual(str(e), "unclosed token: line 1, column 0") |
1082 | |
1083 |
Running landing tests failed /ci.breezy- vcs.org/ job/brz/ job/brz- land/668/
https:/