~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-11 21:41:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080711214124-qi09irlj7pd5cuzg
Shortcut the case when one revision is in the ancestry of the other.

At the cost of a heads() check, when one parent supersedes, we don't have to extract
the text for the other. Changes merge time from 3m37s => 3m21s. Using a
CachingParentsProvider would drop the time down to 3m11s.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        deprecated_function,
44
44
        one_three
45
45
        )
46
 
from bzrlib.trace import warning
 
46
from bzrlib.trace import mutter, warning
47
47
 
48
48
 
49
49
# TODO: Rather than building a changeset object, we should probably
99
99
        ud[2] = ud[2].replace('-1,0', '-0,0')
100
100
    elif not newlines:
101
101
        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'
102
105
 
103
106
    for line in ud:
104
107
        to_file.write(line)
367
370
                return branch.basis_tree()
368
371
        else:
369
372
            return tree
370
 
    return spec.as_tree(branch)
 
373
    if not spec.needs_branch():
 
374
        branch = _mod_branch.Branch.open(spec.get_branch())
 
375
    revision_id = spec.as_revision_id(branch)
 
376
    return branch.repository.revision_tree(revision_id)
371
377
 
372
378
 
373
379
def _relative_paths_in_tree(tree, paths):
436
442
    return timestamp.format_patch_date(mtime)
437
443
 
438
444
 
 
445
def _raise_if_nonexistent(paths, old_tree, new_tree):
 
446
    """Complain if paths are not in either inventory or tree.
 
447
 
 
448
    It's OK with the files exist in either tree's inventory, or 
 
449
    if they exist in the tree but are not versioned.
 
450
    
 
451
    This can be used by operations such as bzr status that can accept
 
452
    unknown or ignored files.
 
453
    """
 
454
    mutter("check paths: %r", paths)
 
455
    if not paths:
 
456
        return
 
457
    s = old_tree.filter_unversioned_files(paths)
 
458
    s = new_tree.filter_unversioned_files(s)
 
459
    s = [path for path in s if not new_tree.has_filename(path)]
 
460
    if s:
 
461
        raise errors.PathsDoNotExist(sorted(s))
 
462
 
 
463
 
439
464
@deprecated_function(one_three)
440
465
def get_prop_change(meta_modified):
441
466
    if meta_modified:
657
682
                 path_encoding='utf-8'):
658
683
        DiffPath.__init__(self, old_tree, new_tree, to_file, path_encoding)
659
684
        self.command_template = command_template
660
 
        self._root = osutils.mkdtemp(prefix='bzr-diff-')
 
685
        self._root = tempfile.mkdtemp(prefix='bzr-diff-')
661
686
 
662
687
    @classmethod
663
688
    def from_string(klass, command_string, old_tree, new_tree, to_file,
849
874
                return path.encode(self.path_encoding, "replace")
850
875
        for (file_id, paths, changed_content, versioned, parent, name, kind,
851
876
             executable) in sorted(iterator, key=changes_key):
852
 
            # The root does not get diffed, and items with no known kind (that
853
 
            # is, missing) in both trees are skipped as well.
854
 
            if parent == (None, None) or kind == (None, None):
 
877
            if parent == (None, None):
855
878
                continue
856
879
            oldpath, newpath = paths
857
880
            oldpath_encoded = get_encoded_path(paths[0])