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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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 bzrlib.lazy_import import lazy_import
 
20
 
 
21
lazy_import(globals(), """
19
22
import errno
20
 
import os
21
 
 
22
 
from .lazy_import import lazy_import
23
 
 
24
 
lazy_import(globals(), """
25
23
import gzip
26
24
import itertools
 
25
import os
 
26
from StringIO import StringIO
27
27
 
28
 
from breezy import (
 
28
from bzrlib import (
29
29
    bencode,
30
30
    errors,
31
31
    patiencediff,
32
32
    ui,
33
33
    )
34
34
""")
35
 
from .sixish import (
36
 
    BytesIO,
37
 
    range,
38
 
    )
39
35
 
40
36
 
41
37
def topo_iter_keys(vf, keys=None):
118
114
        diff = MultiParent([])
119
115
        def next_block(p):
120
116
            try:
121
 
                return next(block_iter[p])
 
117
                return block_iter[p].next()
122
118
            except StopIteration:
123
119
                return None
124
120
        cur_block = [next_block(p) for p, i in enumerate(block_iter)]
169
165
        """Contruct a fulltext from this diff and its parents"""
170
166
        mpvf = MultiMemoryVersionedFile()
171
167
        for num, parent in enumerate(parents):
172
 
            mpvf.add_version(BytesIO(parent).readlines(), num, [])
173
 
        mpvf.add_diff(self, 'a', list(range(len(parents))))
 
168
            mpvf.add_version(StringIO(parent).readlines(), num, [])
 
169
        mpvf.add_diff(self, 'a', range(len(parents)))
174
170
        return mpvf.get_line_list(['a'])[0]
175
171
 
176
172
    @classmethod
177
173
    def from_texts(cls, text, parents=()):
178
174
        """Produce a MultiParent from a text and list of parent text"""
179
 
        return cls.from_lines(BytesIO(text).readlines(),
180
 
                              [BytesIO(p).readlines() for p in parents])
 
175
        return cls.from_lines(StringIO(text).readlines(),
 
176
                              [StringIO(p).readlines() for p in parents])
181
177
 
182
178
    def to_patch(self):
183
179
        """Yield text lines for a patch"""
194
190
    @classmethod
195
191
    def from_patch(cls, text):
196
192
        """Create a MultiParent from its string form"""
197
 
        return cls._from_patch(BytesIO(text))
 
193
        return cls._from_patch(StringIO(text))
198
194
 
199
195
    @staticmethod
200
196
    def _from_patch(lines):
204
200
        cur_line = None
205
201
        while(True):
206
202
            try:
207
 
                cur_line = next(line_iter)
 
203
                cur_line = line_iter.next()
208
204
            except StopIteration:
209
205
                break
210
206
            if cur_line[0] == 'i':
211
207
                num_lines = int(cur_line.split(' ')[1])
212
 
                hunk_lines = [next(line_iter) for _ in range(num_lines)]
 
208
                hunk_lines = [line_iter.next() for x in xrange(num_lines)]
213
209
                hunk_lines[-1] = hunk_lines[-1][:-1]
214
210
                hunks.append(NewText(hunk_lines))
215
211
            elif cur_line[0] == '\n':
339
335
            return False
340
336
        if len(parent_ids) == 0:
341
337
            return True
342
 
        for ignored in range(self.snapshot_interval):
 
338
        for ignored in xrange(self.snapshot_interval):
343
339
            if len(parent_ids) == 0:
344
340
                return False
345
341
            version_ids = parent_ids
403
399
            raise ValueError()
404
400
        revisions = set(vf.versions())
405
401
        total = len(revisions)
406
 
        with ui.ui_factory.nested_progress_bar() as pb:
 
402
        pb = ui.ui_factory.nested_progress_bar()
 
403
        try:
407
404
            while len(revisions) > 0:
408
405
                added = set()
409
406
                for revision in revisions:
429
426
                    pb.update(gettext('Importing revisions'),
430
427
                              (total - len(revisions)) + len(added), total)
431
428
                revisions = [r for r in revisions if r not in added]
 
429
        finally:
 
430
            pb.finished()
432
431
 
433
432
    def select_snapshots(self, vf):
434
433
        """Determine which versions to add as snapshots"""
560
559
        infile = open(self._filename + '.mpknit', 'rb')
561
560
        try:
562
561
            infile.seek(start)
563
 
            sio = BytesIO(infile.read(count))
 
562
            sio = StringIO(infile.read(count))
564
563
        finally:
565
564
            infile.close()
566
565
        zip_file = gzip.GzipFile(None, mode='rb', fileobj=sio)
593
592
    def destroy(self):
594
593
        try:
595
594
            os.unlink(self._filename + '.mpknit')
596
 
        except OSError as e:
 
595
        except OSError, e:
597
596
            if e.errno != errno.ENOENT:
598
597
                raise
599
598
        try:
600
599
            os.unlink(self._filename + '.mpidx')
601
 
        except OSError as e:
 
600
        except OSError, e:
602
601
            if e.errno != errno.ENOENT:
603
602
                raise
604
603
 
644
643
                start, end, kind, data, iterator = self.cursor[req_version_id]
645
644
            except KeyError:
646
645
                iterator = self.diffs.get_diff(req_version_id).range_iterator()
647
 
                start, end, kind, data = next(iterator)
 
646
                start, end, kind, data = iterator.next()
648
647
            if start > req_start:
649
648
                iterator = self.diffs.get_diff(req_version_id).range_iterator()
650
 
                start, end, kind, data = next(iterator)
 
649
                start, end, kind, data = iterator.next()
651
650
 
652
651
            # find the first hunk relevant to the request
653
652
            while end <= req_start:
654
 
                start, end, kind, data = next(iterator)
 
653
                start, end, kind, data = iterator.next()
655
654
            self.cursor[req_version_id] = start, end, kind, data, iterator
656
655
            # if the hunk can't satisfy the whole request, split it in two,
657
656
            # and leave the second half for later.
675
674
 
676
675
 
677
676
def gzip_string(lines):
678
 
    sio = BytesIO()
 
677
    sio = StringIO()
679
678
    data_file = gzip.GzipFile(None, mode='wb', fileobj=sio)
680
679
    data_file.writelines(lines)
681
680
    data_file.close()