1235
1235
class InterDirStateTree(InterTree):
1236
1236
"""Fast path optimiser for changes_from with dirstate trees."""
1238
def __init__(self, source, target):
1239
super(InterDirStateTree, self).__init__(source, target)
1240
if not InterDirStateTree.is_compatible(source, target):
1241
raise Exception, "invalid source %r and target %r" % (source, target)
1239
def revision_tree_from_workingtree(tree):
1240
"""Create a revision tree from a working tree."""
1241
revid = tree.commit('save tree', allow_pointless=True)
1242
return tree.branch.repository.revision_tree(revid)
1243
_from_tree_converter = revision_tree_from_workingtree
1244
def make_source_parent_tree(source, target):
1245
"""Change the source tree into a parent of the target."""
1246
revid = source.commit('record tree')
1247
target.branch.repository.fetch(source.branch.repository, revid)
1248
target.set_parent_ids([revid])
1249
return target.basis_tree(), target
1244
1250
_matching_from_tree_format = WorkingTreeFormat4()
1245
1251
_matching_to_tree_format = WorkingTreeFormat4()
1246
_to_tree_converter = staticmethod(lambda x: x)
1252
_test_mutable_trees_to_test_trees = make_source_parent_tree
1255
def compare(self, want_unchanged=False, specific_files=None,
1256
extra_trees=None, require_versioned=False, include_root=False):
1257
"""Return the changes from source to target.
1259
:return: A TreeDelta.
1260
:param specific_files: An optional list of file paths to restrict the
1261
comparison to. When mapping filenames to ids, all matches in all
1262
trees (including optional extra_trees) are used, and all children of
1263
matched directories are included.
1264
:param want_unchanged: An optional boolean requesting the inclusion of
1265
unchanged entries in the result.
1266
:param extra_trees: An optional list of additional trees to use when
1267
mapping the contents of specific_files (paths) to file_ids.
1268
:param require_versioned: An optional boolean (defaults to False). When
1269
supplied and True all the 'specific_files' must be versioned, or
1270
a PathsNotVersionedError will be thrown.
1272
# NB: show_status depends on being able to pass in non-versioned files
1273
# and report them as unknown
1274
trees = (self.source,)
1275
if extra_trees is not None:
1276
trees = trees + tuple(extra_trees)
1277
# target is usually the newer tree:
1278
specific_file_ids = self.target.paths2ids(specific_files, trees,
1279
require_versioned=require_versioned)
1280
from bzrlib import delta
1281
if specific_files and not specific_file_ids:
1282
# All files are unversioned, so just return an empty delta
1283
# _compare_trees would think we want a complete delta
1284
return delta.TreeDelta()
1285
return delta._compare_trees(self.source, self.target, want_unchanged,
1286
specific_file_ids, include_root)
1249
1289
def is_compatible(source, target):