/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-06-30 10:19:02 UTC
  • mfrom: (6973.7.13 python3-g-real)
  • Revision ID: breezy.the.bot@gmail.com-20180630101902-thpqkbi44kqom06g
Fix more tests.

Merged from https://code.launchpad.net/~jelmer/brz/python3-g/+merge/348134

Show diffs side-by-side

added added

removed removed

Lines of Context:
186
186
                yield line
187
187
 
188
188
    def patch_len(self):
189
 
        return len(''.join(self.to_patch()))
 
189
        return len(b''.join(self.to_patch()))
190
190
 
191
191
    def zipped_patch_len(self):
192
192
        return len(gzip_string(self.to_patch()))
202
202
        line_iter = iter(lines)
203
203
        hunks = []
204
204
        cur_line = None
205
 
        while(True):
 
205
        while True:
206
206
            try:
207
207
                cur_line = next(line_iter)
208
208
            except StopIteration:
209
209
                break
210
 
            if cur_line[0] == 'i':
211
 
                num_lines = int(cur_line.split(' ')[1])
 
210
            first_char = cur_line[0:1]
 
211
            if first_char == b'i':
 
212
                num_lines = int(cur_line.split(b' ')[1])
212
213
                hunk_lines = [next(line_iter) for _ in range(num_lines)]
213
214
                hunk_lines[-1] = hunk_lines[-1][:-1]
214
215
                hunks.append(NewText(hunk_lines))
215
 
            elif cur_line[0] == '\n':
216
 
                hunks[-1].lines[-1] += '\n'
 
216
            elif first_char == b'\n':
 
217
                hunks[-1].lines[-1] += b'\n'
217
218
            else:
218
 
                if not (cur_line[0] == 'c'):
219
 
                    raise AssertionError(cur_line[0])
 
219
                if not (first_char == b'c'):
 
220
                    raise AssertionError(first_char)
220
221
                parent, parent_pos, child_pos, num_lines =\
221
 
                    [int(v) for v in cur_line.split(' ')[1:]]
 
222
                    [int(v) for v in cur_line.split(b' ')[1:]]
222
223
                hunks.append(ParentText(parent, parent_pos, child_pos,
223
224
                                        num_lines))
224
225
        return MultiParent(hunks)
279
280
        return 'NewText(%r)' % self.lines
280
281
 
281
282
    def to_patch(self):
282
 
        yield 'i %d\n' % len(self.lines)
 
283
        yield b'i %d\n' % len(self.lines)
283
284
        for line in self.lines:
284
285
            yield line
285
 
        yield '\n'
 
286
        yield b'\n'
286
287
 
287
288
 
288
289
class ParentText(object):
297
298
        self.num_lines = num_lines
298
299
 
299
300
    def _as_dict(self):
300
 
        return dict(parent=self.parent, parent_pos=self.parent_pos,
301
 
                    child_pos=self.child_pos, num_lines=self.num_lines)
 
301
        return {b'parent': self.parent,
 
302
                b'parent_pos': self.parent_pos,
 
303
                b'child_pos': self.child_pos,
 
304
                b'num_lines': self.num_lines}
302
305
 
303
306
    def __repr__(self):
304
307
        return ('ParentText(%(parent)r, %(parent_pos)r, %(child_pos)r,'
310
313
        return self._as_dict() == other._as_dict()
311
314
 
312
315
    def to_patch(self):
313
 
        yield ('c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'
 
316
        yield (b'c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'
314
317
               % self._as_dict())
315
318
 
316
319
 
410
413
                    parents = vf.get_parents(revision)
411
414
                    if [p for p in parents if p not in self._parents] != []:
412
415
                        continue
413
 
                    lines = [a + ' ' + l for a, l in
 
416
                    lines = [a + b' ' + l for a, l in
414
417
                             vf.annotate(revision)]
415
418
                    if snapshots is None:
416
419
                        force_snapshot = None
573
576
            start = outfile.tell()
574
577
            with gzip.GzipFile(None, mode='ab', fileobj=outfile) as zipfile:
575
578
                zipfile.writelines(itertools.chain(
576
 
                    ['version %s\n' % version_id], diff.to_patch()))
 
579
                    [b'version %s\n' % version_id], diff.to_patch()))
577
580
            end = outfile.tell()
578
581
        self._diff_offset[version_id] = (start, end-start)
579
582
        self._parents[version_id] = parent_ids