43
44
deprecated_function,
46
from bzrlib.trace import mutter, warning
47
from bzrlib.trace import mutter, note, warning
49
50
# TODO: Rather than building a changeset object, we should probably
278
def _get_trees_to_diff(path_list, revision_specs, old_url, new_url):
279
def _get_trees_to_diff(path_list, revision_specs, old_url, new_url,
279
281
"""Get the trees and specific files to diff given a list of paths.
281
283
This method works out the trees to be diff'ed and the files of
293
295
The url of the new branch or tree. If None, the tree to use is
294
296
taken from the first path, if any, or the current working tree.
298
if True and a view is set, apply the view or check that the paths
296
301
a tuple of (old_tree, new_tree, specific_files, extra_trees) where
297
302
extra_trees is a sequence of additional trees to search in for
331
336
working_tree, branch, relpath = \
332
337
bzrdir.BzrDir.open_containing_tree_or_branch(old_url)
333
338
if consider_relpath and relpath != '':
339
if working_tree is not None and apply_view:
340
_check_path_in_view(working_tree, relpath)
334
341
specific_files.append(relpath)
335
342
old_tree = _get_tree_to_diff(old_revision_spec, working_tree, branch)
341
348
working_tree, branch, relpath = \
342
349
bzrdir.BzrDir.open_containing_tree_or_branch(new_url)
343
350
if consider_relpath and relpath != '':
351
if working_tree is not None and apply_view:
352
_check_path_in_view(working_tree, relpath)
344
353
specific_files.append(relpath)
345
354
new_tree = _get_tree_to_diff(new_revision_spec, working_tree, branch,
346
355
basis_is_default=working_tree is None)
348
357
# Get the specific files (all files is None, no files is [])
349
358
if make_paths_wt_relative and working_tree is not None:
350
other_paths = _relative_paths_in_tree(working_tree, other_paths)
360
from bzrlib.builtins import safe_relpath_files
361
other_paths = safe_relpath_files(working_tree, other_paths,
362
apply_view=apply_view)
363
except errors.FileInWrongBranch:
364
raise errors.BzrCommandError("Files are in different branches")
351
365
specific_files.extend(other_paths)
352
366
if len(specific_files) == 0:
353
367
specific_files = None
368
if (working_tree is not None and working_tree.supports_views()
370
view_files = working_tree.views.lookup_view()
372
specific_files = view_files
373
view_str = views.view_display_str(view_files)
374
note("*** ignoring files outside view: %s" % view_str)
355
376
# Get extra trees that ought to be searched for file-ids
356
377
extra_trees = None
359
380
return old_tree, new_tree, specific_files, extra_trees
383
def _check_path_in_view(tree, relpath):
384
"""If a working tree has a view enabled, check the path is within it."""
385
if tree.supports_views():
386
view_files = tree.views.lookup_view()
387
if view_files and not osutils.is_inside_any(view_files, relpath):
388
raise errors.FileOutsideView(relpath, view_files)
362
391
def _get_tree_to_diff(spec, tree=None, branch=None, basis_is_default=True):
363
392
if branch is None and tree is not None:
364
393
branch = tree.branch
376
405
return branch.repository.revision_tree(revision_id)
379
def _relative_paths_in_tree(tree, paths):
380
"""Get the relative paths within a working tree.
382
Each path may be either an absolute path or a path relative to the
383
current working directory.
386
for filename in paths:
388
result.append(tree.relpath(osutils.dereference_path(filename)))
389
except errors.PathNotChild:
390
raise errors.BzrCommandError("Files are in different branches")
394
408
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
395
409
external_diff_options=None,
396
410
old_label='a/', new_label='b/',