/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/multiparent.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from __future__ import absolute_import
18
18
 
19
 
from breezy.lazy_import import lazy_import
 
19
import errno
 
20
import os
 
21
 
 
22
from .lazy_import import lazy_import
20
23
 
21
24
lazy_import(globals(), """
22
 
import errno
23
25
import gzip
24
26
import itertools
25
 
import os
26
 
from StringIO import StringIO
27
27
 
28
28
from breezy import (
29
29
    bencode,
32
32
    ui,
33
33
    )
34
34
""")
 
35
from .sixish import (
 
36
    BytesIO,
 
37
    )
35
38
 
36
39
 
37
40
def topo_iter_keys(vf, keys=None):
165
168
        """Contruct a fulltext from this diff and its parents"""
166
169
        mpvf = MultiMemoryVersionedFile()
167
170
        for num, parent in enumerate(parents):
168
 
            mpvf.add_version(StringIO(parent).readlines(), num, [])
 
171
            mpvf.add_version(BytesIO(parent).readlines(), num, [])
169
172
        mpvf.add_diff(self, 'a', range(len(parents)))
170
173
        return mpvf.get_line_list(['a'])[0]
171
174
 
172
175
    @classmethod
173
176
    def from_texts(cls, text, parents=()):
174
177
        """Produce a MultiParent from a text and list of parent text"""
175
 
        return cls.from_lines(StringIO(text).readlines(),
176
 
                              [StringIO(p).readlines() for p in parents])
 
178
        return cls.from_lines(BytesIO(text).readlines(),
 
179
                              [BytesIO(p).readlines() for p in parents])
177
180
 
178
181
    def to_patch(self):
179
182
        """Yield text lines for a patch"""
190
193
    @classmethod
191
194
    def from_patch(cls, text):
192
195
        """Create a MultiParent from its string form"""
193
 
        return cls._from_patch(StringIO(text))
 
196
        return cls._from_patch(BytesIO(text))
194
197
 
195
198
    @staticmethod
196
199
    def _from_patch(lines):
559
562
        infile = open(self._filename + '.mpknit', 'rb')
560
563
        try:
561
564
            infile.seek(start)
562
 
            sio = StringIO(infile.read(count))
 
565
            sio = BytesIO(infile.read(count))
563
566
        finally:
564
567
            infile.close()
565
568
        zip_file = gzip.GzipFile(None, mode='rb', fileobj=sio)
592
595
    def destroy(self):
593
596
        try:
594
597
            os.unlink(self._filename + '.mpknit')
595
 
        except OSError, e:
 
598
        except OSError as e:
596
599
            if e.errno != errno.ENOENT:
597
600
                raise
598
601
        try:
599
602
            os.unlink(self._filename + '.mpidx')
600
 
        except OSError, e:
 
603
        except OSError as e:
601
604
            if e.errno != errno.ENOENT:
602
605
                raise
603
606
 
674
677
 
675
678
 
676
679
def gzip_string(lines):
677
 
    sio = StringIO()
 
680
    sio = BytesIO()
678
681
    data_file = gzip.GzipFile(None, mode='wb', fileobj=sio)
679
682
    data_file.writelines(lines)
680
683
    data_file.close()