/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bundle/serializer/v4.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-03 23:48:08 UTC
  • mfrom: (7316 work)
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190603234808-15yk5c7054tj8e2b
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import bz2
20
20
import re
21
21
 
22
 
from .... import (
 
22
from ... import (
23
23
    bencode,
24
24
    errors,
25
25
    iterablefile,
31
31
    trace,
32
32
    ui,
33
33
    )
34
 
from ... import (
 
34
from ...bzr import (
35
35
    pack,
36
36
    serializer,
37
37
    versionedfile as _mod_versionedfile,
38
38
    )
39
 
from .. import bundle_data, serializer as bundle_serializer
40
 
from ....i18n import ngettext
41
 
from ....sixish import (
 
39
from ...bundle import bundle_data, serializer as bundle_serializer
 
40
from ...i18n import ngettext
 
41
from ...sixish import (
42
42
    BytesIO,
43
43
    viewitems,
44
44
    )
62
62
        # parents first, and then grab the ordered requests.
63
63
        needed_ids = [k[-1] for k in self.present_parents]
64
64
        needed_ids.extend([k[-1] for k in self.ordered_keys])
65
 
        inv_to_lines = self.repo._serializer.write_inventory_to_chunks
 
65
        inv_to_bytes = self.repo._serializer.write_inventory_to_string
66
66
        for inv in self.repo.iter_inventories(needed_ids):
67
67
            revision_id = inv.revision_id
68
68
            key = (revision_id,)
72
72
                parent_ids = None
73
73
            else:
74
74
                parent_ids = [k[-1] for k in self.parent_map[key]]
75
 
            as_chunks = inv_to_lines(inv)
76
 
            self._process_one_record(key, as_chunks)
 
75
            as_bytes = inv_to_bytes(inv)
 
76
            self._process_one_record(key, (as_bytes,))
77
77
            if parent_ids is None:
78
78
                continue
79
79
            diff = self.diffs.pop(key)
80
 
            sha1 = osutils.sha_strings(as_chunks)
 
80
            sha1 = osutils.sha_string(as_bytes)
81
81
            yield revision_id, parent_ids, sha1, diff
82
82
 
83
83
 
181
181
        """
182
182
        name = self.encode_name(repo_kind, revision_id, file_id)
183
183
        encoded_metadata = bencode.bencode(metadata)
184
 
        self._container.add_bytes_record([encoded_metadata], len(encoded_metadata), [(name, )])
 
184
        self._container.add_bytes_record(encoded_metadata, [(name, )])
185
185
        if metadata[b'storage_kind'] != b'header':
186
 
            self._container.add_bytes_record([bytes], len(bytes), [])
 
186
            self._container.add_bytes_record(bytes, [])
187
187
 
188
188
 
189
189
class BundleReader(object):
368
368
        """Generate mpdiffs by serializing inventories.
369
369
 
370
370
        The current repository only has part of the tree shape information in
371
 
        the 'inventories' vf. So we use serializer.write_inventory_to_lines to
 
371
        the 'inventories' vf. So we use serializer.write_inventory_to_string to
372
372
        get a 'full' representation of the tree shape, and then generate
373
373
        mpdiffs on that data stream. This stream can then be reconstructed on
374
374
        the other side.
626
626
                    present_parent_ids.append(p_id)
627
627
                else:
628
628
                    ghosts.add(p_id)
629
 
            to_lines = self._source_serializer.write_inventory_to_chunks
 
629
            to_string = self._source_serializer.write_inventory_to_string
630
630
            for parent_inv in self._repository.iter_inventories(
631
631
                    present_parent_ids):
632
 
                p_text = b''.join(to_lines(parent_inv))
 
632
                p_text = to_string(parent_inv)
633
633
                inventory_cache[parent_inv.revision_id] = parent_inv
634
634
                cached_parent_texts[parent_inv.revision_id] = p_text
635
635
                inventory_text_cache[parent_inv.revision_id] = p_text
670
670
                # as lines and then cast back to a string.
671
671
                target_lines = multiparent.MultiParent.from_patch(bytes
672
672
                                                                  ).to_lines(p_texts)
673
 
                sha1 = osutils.sha_strings(target_lines)
 
673
                inv_text = b''.join(target_lines)
 
674
                del target_lines
 
675
                sha1 = osutils.sha_string(inv_text)
674
676
                if sha1 != metadata[b'sha1']:
675
677
                    raise errors.BadBundle("Can't convert to target format")
676
678
                # Add this to the cache so we don't have to extract it again.
677
 
                inventory_text_cache[revision_id] = b''.join(target_lines)
678
 
                target_inv = self._source_serializer.read_inventory_from_lines(
679
 
                    target_lines)
680
 
                del target_lines
 
679
                inventory_text_cache[revision_id] = inv_text
 
680
                target_inv = self._source_serializer.read_inventory_from_string(
 
681
                    inv_text)
681
682
                self._handle_root(target_inv, parent_ids)
682
683
                parent_inv = None
683
684
                if parent_ids: