247
247
trailing_space_when_empty=True)
249
249
# Add an extra blank space at the end
250
self.to_file.write('\n')
250
self.to_file.write(b'\n')
252
252
def _write_action(self, name, parameters, properties=None):
253
253
if properties is None:
255
255
p_texts = ['%s:%s' % v for v in properties]
256
self.to_file.write('=== ')
256
self.to_file.write(b'=== ')
257
257
self.to_file.write(' '.join([name]+parameters).encode('utf-8'))
258
258
self.to_file.write(' // '.join(p_texts).encode('utf-8'))
259
self.to_file.write('\n')
259
self.to_file.write(b'\n')
261
261
def _write_delta(self, new_tree, old_tree, default_revision_id,
404
404
for line in self._next():
405
405
# The bzr header is terminated with a blank line
406
406
# which does not start with '#'
407
if line is None or line == '\n':
407
if line is None or line == b'\n':
409
if not line.startswith('#'):
409
if not line.startswith(b'#'):
411
411
found_something = True
412
412
self._handle_next(line)
418
418
def _read_next_entry(self, line, indent=1):
419
419
"""Read in a key-value pair
421
if not line.startswith('#'):
421
if not line.startswith(b'#'):
422
422
raise errors.MalformedHeader('Bzr header did not start with #')
423
423
line = line[1:-1].decode('utf-8') # Remove the '#' and '\n'
424
424
if line[:indent] == ' '*indent:
425
425
line = line[indent:]
427
return None, None# Ignore blank lines
427
return None, None # Ignore blank lines
429
429
loc = line.find(': ')
458
458
value = value.encode('utf8')
459
459
elif key in ('parent_ids'):
460
460
value = [v.encode('utf8') for v in value]
461
elif key in ('testament_sha1'):
462
value = value.encode('ascii')
461
463
setattr(revision_info, key, value)
463
465
raise errors.MalformedHeader('Duplicated Key: %s' % key)
493
495
#mutter('_read_one_patch: %r' % self._next_line)
494
496
# Peek and see if there are no patches
495
if self._next_line is None or self._next_line.startswith('#'):
497
if self._next_line is None or self._next_line.startswith(b'#'):
496
498
return None, [], False
500
502
for line in self._next():
502
if not line.startswith('==='):
504
if not line.startswith(b'==='):
503
505
raise errors.MalformedPatches('The first line of all patches'
504
506
' should be a bzr meta line "==="'
506
508
action = line[4:-1].decode('utf-8')
507
elif line.startswith('... '):
508
action += line[len('... '):-1].decode('utf-8')
509
elif line.startswith(b'... '):
510
action += line[len(b'... '):-1].decode('utf-8')
510
512
if (self._next_line is not None and
511
self._next_line.startswith('===')):
513
self._next_line.startswith(b'===')):
512
514
return action, lines, True
513
elif self._next_line is None or self._next_line.startswith('#'):
515
elif self._next_line is None or self._next_line.startswith(b'#'):
514
516
return action, lines, False
518
elif not line.startswith('... '):
520
elif not line.startswith(b'... '):
519
521
lines.append(line)
521
523
return action, lines, False