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
275
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,
276
278
"""Get the trees and specific files to diff given a list of paths.
278
280
This method works out the trees to be diff'ed and the files of
290
292
The url of the new branch or tree. If None, the tree to use is
291
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
293
298
a tuple of (old_tree, new_tree, specific_files, extra_trees) where
294
299
extra_trees is a sequence of additional trees to search in for
328
333
working_tree, branch, relpath = \
329
334
bzrdir.BzrDir.open_containing_tree_or_branch(old_url)
330
335
if consider_relpath and relpath != '':
336
if working_tree is not None and apply_view:
337
_check_path_in_view(working_tree, relpath)
331
338
specific_files.append(relpath)
332
339
old_tree = _get_tree_to_diff(old_revision_spec, working_tree, branch)
338
345
working_tree, branch, relpath = \
339
346
bzrdir.BzrDir.open_containing_tree_or_branch(new_url)
340
347
if consider_relpath and relpath != '':
348
if working_tree is not None and apply_view:
349
_check_path_in_view(working_tree, relpath)
341
350
specific_files.append(relpath)
342
351
new_tree = _get_tree_to_diff(new_revision_spec, working_tree, branch,
343
352
basis_is_default=working_tree is None)
345
354
# Get the specific files (all files is None, no files is [])
346
355
if make_paths_wt_relative and working_tree is not None:
347
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")
348
362
specific_files.extend(other_paths)
349
363
if len(specific_files) == 0:
350
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)
352
373
# Get extra trees that ought to be searched for file-ids
353
374
extra_trees = None
356
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)
359
388
def _get_tree_to_diff(spec, tree=None, branch=None, basis_is_default=True):
360
389
if branch is None and tree is not None:
361
390
branch = tree.branch
370
399
return spec.as_tree(branch)
373
def _relative_paths_in_tree(tree, paths):
374
"""Get the relative paths within a working tree.
376
Each path may be either an absolute path or a path relative to the
377
current working directory.
380
for filename in paths:
382
result.append(tree.relpath(osutils.dereference_path(filename)))
383
except errors.PathNotChild:
384
raise errors.BzrCommandError("Files are in different branches")
388
402
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
389
403
external_diff_options=None,
390
404
old_label='a/', new_label='b/',