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
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.
28
31
def internal_diff(old_filename, oldlines, new_filename, newlines, to_file,
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)
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)
57
62
# work-around for difflib being too smart for its own good
287
292
for path, file_id, kind in delta.removed:
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:
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,
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:
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,