~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Ian Clatworthy
  • Date: 2007-12-04 06:31:26 UTC
  • mto: (3118.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3119.
  • Revision ID: ian.clatworthy@internode.on.net-20071204063126-vifma88qptj13pyk
Test various --old and --new combinations

Show diffs side-by-side

added added

removed removed

Lines of Context:
388
388
            specific_files = path_list or None
389
389
            return old_tree, new_tree, specific_files, None
390
390
 
391
 
    # If no path is given, assume the current directory
392
391
    if path_list is None or len(path_list) == 0:
 
392
        # If no path is given, assume the current directory
393
393
        default_location = u'.'
394
394
        other_paths = []
395
395
        check_paths = True
403
403
        check_paths = True
404
404
 
405
405
    # Get the old location
 
406
    specific_files = []
406
407
    if old_url is None:
407
408
        old_url = default_location
408
409
    working_tree, branch, relpath = \
409
410
        bzrdir.BzrDir.open_containing_tree_or_branch(old_url)
 
411
    if relpath != '':
 
412
        specific_files.append(relpath)
410
413
    old_tree = _get_tree_to_diff(old_revision_spec, working_tree, branch)
411
414
 
412
415
    # Get the new location
415
418
    if new_url != old_url:
416
419
        working_tree, branch, relpath = \
417
420
            bzrdir.BzrDir.open_containing_tree_or_branch(new_url)
 
421
        if relpath != '':
 
422
            specific_files.append(relpath)
418
423
    new_tree = _get_tree_to_diff(new_revision_spec, working_tree, branch,
419
424
        basis_is_default=working_tree is None)
420
425
 
421
 
    # Get the specific files and extra trees
422
 
    specific_files = _relative_files_for_diff(working_tree, relpath,
423
 
        other_paths, check_paths)
 
426
    # Get the specific files (all files is None, no files is [])
 
427
    if check_paths and working_tree is not None:
 
428
        other_paths = _relative_paths_in_tree(working_tree, other_paths)
 
429
    specific_files.extend(other_paths)
 
430
    if len(specific_files) == 0:
 
431
        specific_files = None
 
432
 
 
433
    # Get extra trees that ought to be searched for file-ids
424
434
    extra_trees = None
425
435
    if new_tree != working_tree and working_tree is not None:
426
436
        extra_trees = (working_tree,)
441
451
    return rev_branch.repository.revision_tree(revision_id)
442
452
 
443
453
 
444
 
def _relative_files_for_diff(tree, first_relpath, other_paths, check_paths):
445
 
    """Get the specific files for diff.
 
454
def _relative_paths_in_tree(tree, paths):
 
455
    """Get the relative paths within a working tree.
446
456
 
447
 
    This method converts path arguments to relative paths in a tree.
448
 
    If the tree is None or check_paths is False, other_paths are assumed
449
 
    to be relative already. Otherwise, all arguments must be paths in
450
 
    the working tree.
 
457
    All paths must be existing paths in the working tree.
451
458
    """
452
 
    specific_files = []
453
 
    if first_relpath != '':
454
 
        specific_files.append(first_relpath)
455
 
    if not check_paths or tree is None:
456
 
        specific_files.extend(other_paths)
457
 
    else:
458
 
        for filename in other_paths:
459
 
            try:
460
 
                specific_files.append(tree.relpath(osutils.dereference_path(
461
 
                    filename)))
462
 
            except errors.PathNotChild:
463
 
                raise errors.BzrCommandError("Files are in different branches")
464
 
    if len(specific_files) == 0:
465
 
        specific_files = None
466
 
    return specific_files
 
459
    result = []
 
460
    for filename in paths:
 
461
        try:
 
462
            result.append(tree.relpath(osutils.dereference_path(filename)))
 
463
        except errors.PathNotChild:
 
464
            raise errors.BzrCommandError("Files are in different branches")
 
465
    return result
467
466
 
468
467
 
469
468
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,