~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to gen_changeset.py

  • Committer: John Arbash Meinel
  • Date: 2005-07-16 16:22:04 UTC
  • mto: (1185.82.1 bzr-w-changeset) (0.5.98)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20050716162204-ca86975b99b2742e
Handling international characters, added more test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
248
248
        self.revision_list = [self.target_branch.get_revision(rid) 
249
249
                                for rid in rev_id_list]
250
250
 
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
 
253
        if encode:
 
254
            def write(txt):
 
255
                self.to_file.write(_encode(txt))
 
256
        else:
 
257
            def write(txt):
 
258
                self.to_file.write(txt)
 
259
        if indent > 0:
 
260
            write('#' + (' ' * indent))
252
261
        if key:
253
 
            self.to_file.write('# %s: %s\n' % (key, txt))
 
262
            if txt:
 
263
                write('%s: %s\n' % (key, txt))
 
264
            else:
 
265
                write('%s:\n' % key)
254
266
        else:
255
 
            self.to_file.write('# %s\n' % (txt,))
 
267
            write('%s\n' % (txt,))
256
268
 
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')
283
295
        if rev.message:
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
288
300
 
289
 
        write('')
290
 
        self.to_file.write('\n')
 
301
        write('') # line with just '#'
 
302
        write('', indent=0) # Empty line
291
303
 
292
304
    def _write_footer(self):
293
305
        """Write the stuff that comes after the patches.
312
324
 
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
 
328
 
 
329
        write = self._write
316
330
 
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)
344
358
 
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'
351
365
 
355
369
        rev_id = self.target_rev_id
356
370
        tree = self.target_tree
357
371
 
 
372
        write = self._write
 
373
 
358
374
 
359
375
        def get_text_id_str(file_id, kind, modified=True):
360
376
            """This returns an empty string if guess_text_id == real_text_id.
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
369
385
            else:
370
386
                return ''
371
387
 
372
388
 
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,
376
 
                    encode(path))
 
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(),
382
397
                          self.to_file)
383
398
    
384
399
        for path, file_id, kind in self.delta.added:
385
 
            print >>self.to_file, '*** added %s %s // file-id:%s%s' % (kind,
386
 
                    encode(path),
387
 
                    encode(file_id),
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)),
 
402
                    indent=0)
389
403
            if kind == 'file':
390
404
                diff_file(DEVNULL,
391
405
                          [],
394
408
                          self.to_file)
395
409
    
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,
 
412
                    old_path, new_path,
 
413
                    get_text_id_str(file_id, kind, modified=text_modified)),
 
414
                    indent=0)
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(),
416
431
                              self.to_file)
417
432
    
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)),
 
436
                    indent=0)
421
437
            if kind == 'file':
422
438
                diff_file(pjoin(self.base_label, path),
423
439
                          self.base_tree.get_file(file_id).readlines(),