248
248
self.revision_list = [self.target_branch.get_revision(rid)
249
249
for rid in rev_id_list]
251
def _write(self, txt, key=None):
251
def _write(self, txt, key=None, encode=True, indent=1):
252
from common import encode as _encode
255
self.to_file.write(_encode(txt))
258
self.to_file.write(txt)
260
write('#' + (' ' * indent))
253
self.to_file.write('# %s: %s\n' % (key, txt))
263
write('%s: %s\n' % (key, txt))
255
self.to_file.write('# %s\n' % (txt,))
267
write('%s\n' % (txt,))
257
269
def write_meta_info(self, to_file):
258
270
"""Write out the meta-info portion to the supplied file.
281
293
self.date = format_highres_date(rev.timestamp, offset=rev.timezone)
282
294
write(self.date, key='date')
284
self.to_file.write('# message:\n')
296
write('', key='message')
285
297
for line in rev.message.split('\n'):
286
self.to_file.write('# %s\n' % line)
298
write(txt=line, indent=4)
287
299
self.message = rev.message
290
self.to_file.write('\n')
301
write('') # line with just '#'
302
write('', indent=0) # Empty line
292
304
def _write_footer(self):
293
305
"""Write the stuff that comes after the patches.
313
325
def _write_revisions(self):
314
326
"""Not used. Used for writing multiple revisions."""
315
from common import format_highres_date
327
from common import format_highres_date, encode
317
331
for rev in self.revision_list:
318
332
rev_id = rev.revision_id
319
self.to_file.write('# revision: %s\n' % rev_id)
320
self.to_file.write('# sha1: %s\n' %
321
self.target_branch.get_revision_sha1(rev_id))
333
write(rev_id, key='revision')
334
write(self.target_branch.get_revision_sha1(rev_id),
335
key = 'sha1', indent=4)
322
336
if rev.committer != self.committer:
323
self.to_file.write('# committer: %s\n' % rev.committer)
337
write(rev.committer, key='committer', indent=4)
324
338
date = format_highres_date(rev.timestamp, rev.timezone)
325
339
if date != self.date:
326
self.to_file.write('# date: %s\n' % date)
340
write(date, key='date', indent=4)
327
341
if rev.inventory_id != rev_id:
328
self.to_file.write('# inventory id: %s\n' % rev.inventory_id)
329
self.to_file.write('# inventory sha1: %s\n' % rev.inventory_sha1)
342
write(rev.inventory_id, key='inventory id', indent=4)
343
write(rev.inventory_sha1, key='inventory sha1', indent=4)
330
344
if len(rev.parents) > 0:
331
self.to_file.write('# parents:\n')
345
write(txt='', key='parents', indent=4)
332
346
for parent in rev.parents:
333
347
p_id = parent.revision_id
334
348
p_sha1 = parent.revision_sha1
336
350
warning('Rev id {%s} parent {%s} missing sha hash.'
337
351
% (rev_id, p_id))
338
352
p_sha1 = self.target_branch.get_revision_sha1(p_id)
339
self.to_file.write('# %s\t%s\n' % (p_id, p_sha1))
353
write(p_id + '\t' + p_sha1, indent=7)
340
354
if rev.message and rev.message != self.message:
341
self.to_file.write('# message:\n')
355
write('', key='message', indent=4)
342
356
for line in rev.message.split('\n'):
343
self.to_file.write('# %s\n' % line)
357
write(line, indent=7)
345
359
def _write_diffs(self):
346
360
"""Write out the specific diffs"""
347
361
from bzrlib.diff import internal_diff
348
from common import encode, guess_text_id
362
from common import guess_text_id
349
363
from os.path import join as pjoin
350
364
DEVNULL = '/dev/null'
365
381
kind, modified=modified)
366
382
real_id = tree.inventory[file_id].text_id
367
383
if guess_id != real_id:
368
return ' // text-id:' + encode(real_id)
384
return ' // text-id:' + real_id
373
389
for path, file_id, kind in self.delta.removed:
374
390
# We don't care about text ids for removed files
375
print >>self.to_file, '*** removed %s %s' % (kind,
391
write('*** removed %s %s' % (kind, path), indent=0)
377
392
if kind == 'file' and self.full_remove:
378
393
diff_file(pjoin(self.base_label, path),
379
394
self.base_tree.get_file(file_id).readlines(),
384
399
for path, file_id, kind in self.delta.added:
385
print >>self.to_file, '*** added %s %s // file-id:%s%s' % (kind,
388
get_text_id_str(file_id, kind))
400
write('*** added %s %s // file-id:%s%s' % (kind,
401
path, file_id, get_text_id_str(file_id, kind)),
389
403
if kind == 'file':
390
404
diff_file(DEVNULL,
396
410
for old_path, new_path, file_id, kind, text_modified in self.delta.renamed:
397
print >>self.to_file, '*** renamed %s %s // %s%s' % (kind,
398
encode(old_path), encode(new_path),
399
get_text_id_str(file_id, kind, modified=text_modified))
411
write('*** renamed %s %s // %s%s' % (kind,
413
get_text_id_str(file_id, kind, modified=text_modified)),
400
415
if self.full_rename and kind == 'file':
401
416
diff_file(pjoin(self.base_label, old_path),
402
417
self.base_tree.get_file(file_id).readlines(),
418
433
for path, file_id, kind in self.delta.modified:
419
print >>self.to_file, '*** modified %s %s%s' % (kind,
420
encode(path), get_text_id_str(file_id, kind))
434
write('*** modified %s %s%s' % (kind,
435
path, get_text_id_str(file_id, kind)),
421
437
if kind == 'file':
422
438
diff_file(pjoin(self.base_label, path),
423
439
self.base_tree.get_file(file_id).readlines(),