22
22
from warnings import warn
25
from bzrlib import delta
26
from bzrlib.decorators import needs_read_lock
25
27
from bzrlib.errors import BzrError, BzrCheckError
26
28
from bzrlib import errors
27
29
from bzrlib.inventory import Inventory
30
from bzrlib.inter import InterObject
28
31
from bzrlib.osutils import fingerprint_file
29
32
import bzrlib.revision
30
33
from bzrlib.trace import mutter, note
50
53
trees or versioned trees.
56
def changes_from(self, other, want_unchanged=False, specific_files=None,
57
extra_trees=None, require_versioned=False):
58
"""Return a TreeDelta of the changes from other to this tree.
60
:param other: A tree to compare with.
61
:param specific_files: An optional list of file paths to restrict the
62
comparison to. When mapping filenames to ids, all matches in all
63
trees (including optional extra_trees) are used, and all children of
64
matched directories are included.
65
:param want_unchanged: An optional boolean requesting the inclusion of
66
unchanged entries in the result.
67
:param extra_trees: An optional list of additional trees to use when
68
mapping the contents of specific_files (paths) to file_ids.
69
:param require_versioned: An optional boolean (defaults to False). When
70
supplied and True all the 'specific_files' must be versioned, or
71
a PathsNotVersionedError will be thrown.
73
The comparison will be performed by an InterTree object looked up on
76
# Martin observes that Tree.changes_from returns a TreeDelta and this
77
# may confuse people, because the class name of the returned object is
78
# a synonym of the object referenced in the method name.
79
return InterTree.get(other, self).compare(
80
want_unchanged=want_unchanged,
81
specific_files=specific_files,
82
extra_trees=extra_trees,
83
require_versioned=require_versioned,
53
86
def conflicts(self):
54
87
"""Get a list of the conflicts in the tree.
359
392
interesting_ids.update(new_pending)
360
393
pending = new_pending
361
394
return interesting_ids
397
class InterTree(InterObject):
398
"""This class represents operations taking place between two Trees.
400
Its instances have methods like 'compare' and contain references to the
401
source and target trees these operations are to be carried out on.
403
clients of bzrlib should not need to use InterTree directly, rather they
404
should use the convenience methods on Tree such as 'Tree.compare()' which
405
will pass through to InterTree as appropriate.
411
def compare(self, want_unchanged=False, specific_files=None,
412
extra_trees=None, require_versioned=False):
413
"""Return the changes from source to target.
415
:return: A TreeDelta.
416
:param specific_files: An optional list of file paths to restrict the
417
comparison to. When mapping filenames to ids, all matches in all
418
trees (including optional extra_trees) are used, and all children of
419
matched directories are included.
420
:param want_unchanged: An optional boolean requesting the inclusion of
421
unchanged entries in the result.
422
:param extra_trees: An optional list of additional trees to use when
423
mapping the contents of specific_files (paths) to file_ids.
424
:param require_versioned: An optional boolean (defaults to False). When
425
supplied and True all the 'specific_files' must be versioned, or
426
a PathsNotVersionedError will be thrown.
428
# NB: show_status depends on being able to pass in non-versioned files and
429
# report them as unknown
430
trees = (self.source, self.target)
431
if extra_trees is not None:
432
trees = trees + tuple(extra_trees)
433
specific_file_ids = find_ids_across_trees(specific_files,
434
trees, require_versioned=require_versioned)
435
if specific_files and not specific_file_ids:
436
# All files are unversioned, so just return an empty delta
437
# _compare_trees would think we want a complete delta
438
return delta.TreeDelta()
439
return delta._compare_trees(self.source, self.target, want_unchanged,