~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-21 07:21:10 UTC
  • mfrom: (4029.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090221072110-uf8tjt38l6r3vo6o
Filtered views (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    patiencediff,
37
37
    textfile,
38
38
    timestamp,
 
39
    views,
39
40
    )
40
41
""")
41
42
 
43
44
        deprecated_function,
44
45
        one_three
45
46
        )
46
 
from bzrlib.trace import warning
 
47
from bzrlib.trace import mutter, note, warning
47
48
 
48
49
 
49
50
# TODO: Rather than building a changeset object, we should probably
272
273
                        new_abspath, e)
273
274
 
274
275
 
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,
 
277
    apply_view=True):
276
278
    """Get the trees and specific files to diff given a list of paths.
277
279
 
278
280
    This method works out the trees to be diff'ed and the files of
289
291
    :param new_url:
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.
 
294
    :param apply_view:
 
295
        if True and a view is set, apply the view or check that the paths
 
296
        are within it
292
297
    :returns:
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)
333
340
 
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)
344
353
 
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)
 
356
        try:
 
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()
 
366
            and apply_view):
 
367
            view_files = working_tree.views.lookup_view()
 
368
            if view_files:
 
369
                specific_files = view_files
 
370
                view_str = views.view_display_str(view_files)
 
371
                note("*** ignoring files outside view: %s" % view_str)
351
372
 
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
357
378
 
358
379
 
 
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)
 
386
 
 
387
 
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)
371
400
 
372
401
 
373
 
def _relative_paths_in_tree(tree, paths):
374
 
    """Get the relative paths within a working tree.
375
 
 
376
 
    Each path may be either an absolute path or a path relative to the
377
 
    current working directory.
378
 
    """
379
 
    result = []
380
 
    for filename in paths:
381
 
        try:
382
 
            result.append(tree.relpath(osutils.dereference_path(filename)))
383
 
        except errors.PathNotChild:
384
 
            raise errors.BzrCommandError("Files are in different branches")
385
 
    return result
386
 
 
387
 
 
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/',