~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
347
347
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
348
348
                    external_diff_options=None,
349
349
                    old_label='a/', new_label='b/',
350
 
                    extra_trees=None):
 
350
                    extra_trees=None,
 
351
                    path_encoding='utf8'):
351
352
    """Show in text form the changes from one tree to another.
352
353
 
353
354
    to_files
358
359
 
359
360
    extra_trees
360
361
        If set, more Trees to use for looking up file ids
 
362
 
 
363
    path_encoding
 
364
        If set, the path will be encoded as specified, otherwise is supposed
 
365
        to be utf8
361
366
    """
362
367
    old_tree.lock_read()
363
368
    try:
369
374
            return _show_diff_trees(old_tree, new_tree, to_file,
370
375
                                    specific_files, external_diff_options,
371
376
                                    old_label=old_label, new_label=new_label,
372
 
                                    extra_trees=extra_trees)
 
377
                                    extra_trees=extra_trees,
 
378
                                    path_encoding=path_encoding)
373
379
        finally:
374
380
            new_tree.unlock()
375
381
            if extra_trees is not None:
380
386
 
381
387
 
382
388
def _show_diff_trees(old_tree, new_tree, to_file,
383
 
                     specific_files, external_diff_options, 
 
389
                     specific_files, external_diff_options, path_encoding,
384
390
                     old_label='a/', new_label='b/', extra_trees=None):
385
391
 
386
392
    # GNU Patch uses the epoch date to detect files that are being added
405
411
    has_changes = 0
406
412
    for path, file_id, kind in delta.removed:
407
413
        has_changes = 1
408
 
        print >>to_file, "=== removed %s '%s'" % (kind, path.encode('utf8'))
 
414
        path_encoded = path.encode(path_encoding, "replace")
 
415
        print >>to_file, "=== removed %s '%s'" % (kind, path_encoded)
409
416
        old_name = '%s%s\t%s' % (old_label, path,
410
417
                                 _patch_header_date(old_tree, file_id, path))
411
418
        new_name = '%s%s\t%s' % (new_label, path, EPOCH_DATE)
413
420
                                         new_name, None, None, to_file)
414
421
    for path, file_id, kind in delta.added:
415
422
        has_changes = 1
416
 
        print >>to_file, "=== added %s '%s'" % (kind, path.encode('utf8'))
 
423
        path_encoded = path.encode(path_encoding, "replace")
 
424
        print >>to_file, "=== added %s '%s'" % (kind, path_encoded)
417
425
        old_name = '%s%s\t%s' % (old_label, path, EPOCH_DATE)
418
426
        new_name = '%s%s\t%s' % (new_label, path,
419
427
                                 _patch_header_date(new_tree, file_id, path))
424
432
         text_modified, meta_modified) in delta.renamed:
425
433
        has_changes = 1
426
434
        prop_str = get_prop_change(meta_modified)
427
 
        print >>to_file, "=== renamed %s '%s' => '%s'%s" % (
428
 
                    kind, old_path.encode('utf8'),
429
 
                    new_path.encode('utf8'), prop_str)
 
435
        oldpath_encoded = old_path.encode(path_encoding, "replace")
 
436
        newpath_encoded = new_path.encode(path_encoding, "replace")
 
437
        print >>to_file, "=== renamed %s '%s' => '%s'%s" % (kind,
 
438
                            oldpath_encoded, newpath_encoded, prop_str)
430
439
        old_name = '%s%s\t%s' % (old_label, old_path,
431
440
                                 _patch_header_date(old_tree, file_id,
432
441
                                                    old_path))
439
448
    for path, file_id, kind, text_modified, meta_modified in delta.modified:
440
449
        has_changes = 1
441
450
        prop_str = get_prop_change(meta_modified)
442
 
        print >>to_file, "=== modified %s '%s'%s" % (kind, path.encode('utf8'),
443
 
                                                     prop_str)
 
451
        path_encoded = path.encode(path_encoding, "replace")
 
452
        print >>to_file, "=== modified %s '%s'%s" % (kind,
 
453
                            path_encoded, prop_str)
444
454
        # The file may be in a different location in the old tree (because
445
455
        # the containing dir was renamed, but the file itself was not)
446
456
        old_path = old_tree.id2path(file_id)