43
44
deprecated_function,
46
from bzrlib.trace import warning
47
from bzrlib.trace import mutter, note, warning
49
50
# TODO: Rather than building a changeset object, we should probably
78
79
# both sequences are empty.
79
80
if not oldlines and not newlines:
82
83
if allow_binary is False:
83
84
textfile.check_text_lines(oldlines)
84
85
textfile.check_text_lines(newlines)
99
100
ud[2] = ud[2].replace('-1,0', '-0,0')
100
101
elif not newlines:
101
102
ud[2] = ud[2].replace('+1,0', '+0,0')
102
# work around for difflib emitting random spaces after the label
103
ud[0] = ud[0][:-2] + '\n'
104
ud[1] = ud[1][:-2] + '\n'
107
105
to_file.write(line)
204
202
diffcmd.append('-u')
207
205
diffcmd.extend(diff_opts)
209
207
pipe = _spawn_external_diff(diffcmd, capture_errors=True)
210
208
out,err = pipe.communicate()
211
209
rc = pipe.returncode
213
211
# internal_diff() adds a trailing newline, add one here for consistency
278
def _get_trees_to_diff(path_list, revision_specs, old_url, new_url):
276
def _get_trees_to_diff(path_list, revision_specs, old_url, new_url,
279
278
"""Get the trees and specific files to diff given a list of paths.
281
280
This method works out the trees to be diff'ed and the files of
293
292
The url of the new branch or tree. If None, the tree to use is
294
293
taken from the first path, if any, or the current working tree.
295
if True and a view is set, apply the view or check that the paths
296
298
a tuple of (old_tree, new_tree, specific_files, extra_trees) where
297
299
extra_trees is a sequence of additional trees to search in for
331
333
working_tree, branch, relpath = \
332
334
bzrdir.BzrDir.open_containing_tree_or_branch(old_url)
333
335
if consider_relpath and relpath != '':
336
if working_tree is not None and apply_view:
337
_check_path_in_view(working_tree, relpath)
334
338
specific_files.append(relpath)
335
339
old_tree = _get_tree_to_diff(old_revision_spec, working_tree, branch)
341
345
working_tree, branch, relpath = \
342
346
bzrdir.BzrDir.open_containing_tree_or_branch(new_url)
343
347
if consider_relpath and relpath != '':
348
if working_tree is not None and apply_view:
349
_check_path_in_view(working_tree, relpath)
344
350
specific_files.append(relpath)
345
351
new_tree = _get_tree_to_diff(new_revision_spec, working_tree, branch,
346
352
basis_is_default=working_tree is None)
348
354
# Get the specific files (all files is None, no files is [])
349
355
if make_paths_wt_relative and working_tree is not None:
350
other_paths = _relative_paths_in_tree(working_tree, other_paths)
357
from bzrlib.builtins import safe_relpath_files
358
other_paths = safe_relpath_files(working_tree, other_paths,
359
apply_view=apply_view)
360
except errors.FileInWrongBranch:
361
raise errors.BzrCommandError("Files are in different branches")
351
362
specific_files.extend(other_paths)
352
363
if len(specific_files) == 0:
353
364
specific_files = None
365
if (working_tree is not None and working_tree.supports_views()
367
view_files = working_tree.views.lookup_view()
369
specific_files = view_files
370
view_str = views.view_display_str(view_files)
371
note("*** ignoring files outside view: %s" % view_str)
355
373
# Get extra trees that ought to be searched for file-ids
356
374
extra_trees = None
359
377
return old_tree, new_tree, specific_files, extra_trees
380
def _check_path_in_view(tree, relpath):
381
"""If a working tree has a view enabled, check the path is within it."""
382
if tree.supports_views():
383
view_files = tree.views.lookup_view()
384
if view_files and not osutils.is_inside_any(view_files, relpath):
385
raise errors.FileOutsideView(relpath, view_files)
362
388
def _get_tree_to_diff(spec, tree=None, branch=None, basis_is_default=True):
363
389
if branch is None and tree is not None:
364
390
branch = tree.branch
373
399
return spec.as_tree(branch)
376
def _relative_paths_in_tree(tree, paths):
377
"""Get the relative paths within a working tree.
379
Each path may be either an absolute path or a path relative to the
380
current working directory.
383
for filename in paths:
385
result.append(tree.relpath(osutils.dereference_path(filename)))
386
except errors.PathNotChild:
387
raise errors.BzrCommandError("Files are in different branches")
391
402
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
392
403
external_diff_options=None,
393
404
old_label='a/', new_label='b/',