17
17
from bzrlib.delta import compare_trees
18
18
from bzrlib.errors import BzrError
19
import bzrlib.errors as errors
19
20
from bzrlib.symbol_versioning import *
21
from bzrlib.textfile import check_text_lines
20
22
from bzrlib.trace import mutter
22
24
# TODO: Rather than building a changeset object, we should probably
23
25
# invoke callbacks on an object. That object can either accumulate a
24
26
# list, write them out directly, etc etc.
26
def internal_diff(old_filename, oldlines, new_filename, newlines, to_file):
28
def internal_diff(old_filename, oldlines, new_filename, newlines, to_file,
29
32
# FIXME: difflib is wrong if there is no trailing newline.
41
44
# both sequences are empty.
42
45
if not oldlines and not newlines:
48
if allow_binary is False:
49
check_text_lines(oldlines)
50
check_text_lines(newlines)
45
52
ud = difflib.unified_diff(oldlines, newlines,
46
53
fromfile=old_filename+'\t',
264
270
# TODO: Generation of pseudo-diffs for added/deleted files could
265
271
# be usefully made into a much faster special case.
273
_raise_if_doubly_unversioned(specific_files, old_tree, new_tree)
267
275
if external_diff_options:
268
276
assert isinstance(external_diff_options, basestring)
269
277
opts = external_diff_options.split()
273
281
diff_file = internal_diff
276
283
delta = compare_trees(old_tree, new_tree, want_unchanged=False,
277
284
specific_files=specific_files)
306
313
_maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
307
314
new_label, path, new_tree,
308
315
True, kind, to_file, diff_file)
309
317
return has_changes
320
def _raise_if_doubly_unversioned(specific_files, old_tree, new_tree):
321
"""Complain if paths are not versioned in either tree."""
322
if not specific_files:
324
old_unversioned = old_tree.filter_unversioned_files(specific_files)
325
new_unversioned = new_tree.filter_unversioned_files(specific_files)
326
unversioned = old_unversioned.intersection(new_unversioned)
328
raise errors.PathsNotVersionedError(sorted(unversioned))
331
def _raise_if_nonexistent(paths, old_tree, new_tree):
332
"""Complain if paths are not in either inventory or tree.
334
It's OK with the files exist in either tree's inventory, or
335
if they exist in the tree but are not versioned.
337
This can be used by operations such as bzr status that can accept
338
unknown or ignored files.
340
mutter("check paths: %r", paths)
343
s = old_tree.filter_unversioned_files(paths)
344
s = new_tree.filter_unversioned_files(s)
345
s = [path for path in s if not new_tree.has_filename(path)]
347
raise errors.PathsDoNotExist(sorted(s))
312
350
def get_prop_change(meta_modified):
313
351
if meta_modified: