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',
185
192
def diff_cmd_helper(tree, specific_files, external_diff_options,
186
old_revision_spec=None, new_revision_spec=None):
193
old_revision_spec=None, new_revision_spec=None,
194
old_label='a/', new_label='b/'):
187
195
"""Helper for cmd_diff.
222
230
new_tree = spec_tree(new_revision_spec)
224
232
return show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
225
external_diff_options)
233
external_diff_options,
234
old_label=old_label, new_label=new_label)
228
237
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
229
external_diff_options=None):
238
external_diff_options=None,
239
old_label='a/', new_label='b/'):
230
240
"""Show in text form the changes from one tree to another.
235
245
external_diff_options
236
246
If set, use an external GNU diff and pass these options.
239
248
old_tree.lock_read()
241
250
new_tree.lock_read()
243
252
return _show_diff_trees(old_tree, new_tree, to_file,
244
specific_files, external_diff_options)
253
specific_files, external_diff_options,
254
old_label=old_label, new_label=new_label)
246
256
new_tree.unlock()
251
261
def _show_diff_trees(old_tree, new_tree, to_file,
252
specific_files, external_diff_options):
254
# TODO: Options to control putting on a prefix or suffix, perhaps
255
# as a format string?
262
specific_files, external_diff_options,
263
old_label='a/', new_label='b/' ):
259
265
DEVNULL = '/dev/null'
260
266
# Windows users, don't panic about this filename -- it is a
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: