/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 bzrlib/diff.py

  • Committer: Wouter van Heyst
  • Date: 2006-06-06 12:06:20 UTC
  • mfrom: (1740 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: larstiq@larstiq.dyndns.org-20060606120620-50066b0951e4ef7c
merge bzr.dev 1740

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from bzrlib.delta import compare_trees
18
18
from bzrlib.errors import BzrError
19
19
import bzrlib.errors as errors
 
20
from bzrlib.patiencediff import unified_diff
 
21
import bzrlib.patiencediff
20
22
from bzrlib.symbol_versioning import *
21
23
from bzrlib.textfile import check_text_lines
22
24
from bzrlib.trace import mutter
23
25
 
 
26
 
24
27
# TODO: Rather than building a changeset object, we should probably
25
28
# invoke callbacks on an object.  That object can either accumulate a
26
29
# list, write them out directly, etc etc.
27
30
 
28
31
def internal_diff(old_filename, oldlines, new_filename, newlines, to_file,
29
 
                  allow_binary=False):
30
 
    import difflib
31
 
    
 
32
                  allow_binary=False, sequence_matcher=None,
 
33
                  path_encoding='utf8'):
32
34
    # FIXME: difflib is wrong if there is no trailing newline.
33
35
    # The syntax used by patch seems to be "\ No newline at
34
36
    # end of file" following the last diff line from that
49
51
        check_text_lines(oldlines)
50
52
        check_text_lines(newlines)
51
53
 
52
 
    ud = difflib.unified_diff(oldlines, newlines,
53
 
                              fromfile=old_filename+'\t', 
54
 
                              tofile=new_filename+'\t')
 
54
    if sequence_matcher is None:
 
55
        sequence_matcher = bzrlib.patiencediff.PatienceSequenceMatcher
 
56
    ud = unified_diff(oldlines, newlines,
 
57
                      fromfile=old_filename.encode(path_encoding)+'\t', 
 
58
                      tofile=new_filename.encode(path_encoding)+'\t',
 
59
                      sequencematcher=sequence_matcher)
55
60
 
56
61
    ud = list(ud)
57
62
    # work-around for difflib being too smart for its own good
286
291
    has_changes = 0
287
292
    for path, file_id, kind in delta.removed:
288
293
        has_changes = 1
289
 
        print >>to_file, '=== removed %s %r' % (kind, path)
 
294
        print >>to_file, '=== removed %s %r' % (kind, path.encode('utf8'))
290
295
        old_tree.inventory[file_id].diff(diff_file, old_label + path, old_tree,
291
296
                                         DEVNULL, None, None, to_file)
292
297
    for path, file_id, kind in delta.added:
293
298
        has_changes = 1
294
 
        print >>to_file, '=== added %s %r' % (kind, path)
 
299
        print >>to_file, '=== added %s %r' % (kind, path.encode('utf8'))
295
300
        new_tree.inventory[file_id].diff(diff_file, new_label + path, new_tree,
296
301
                                         DEVNULL, None, None, to_file, 
297
302
                                         reverse=True)
300
305
        has_changes = 1
301
306
        prop_str = get_prop_change(meta_modified)
302
307
        print >>to_file, '=== renamed %s %r => %r%s' % (
303
 
                    kind, old_path, new_path, prop_str)
 
308
                    kind, old_path.encode('utf8'),
 
309
                    new_path.encode('utf8'), prop_str)
304
310
        _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
305
311
                                    new_label, new_path, new_tree,
306
312
                                    text_modified, kind, to_file, diff_file)
307
313
    for path, file_id, kind, text_modified, meta_modified in delta.modified:
308
314
        has_changes = 1
309
315
        prop_str = get_prop_change(meta_modified)
310
 
        print >>to_file, '=== modified %s %r%s' % (kind, path, prop_str)
 
316
        print >>to_file, '=== modified %s %r%s' % (kind, path.encode('utf8'), prop_str)
311
317
        if text_modified:
312
318
            _maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
313
319
                                        new_label, path, new_tree,