873
872
return (file_id, (source_path, target_path), changed_content,
874
873
versioned, parent, name, kind, executable), changes
877
875
def compare(self, want_unchanged=False, specific_files=None,
878
876
extra_trees=None, require_versioned=False, include_root=False,
879
877
want_unversioned=False):
896
894
trees = (self.source,)
897
895
if extra_trees is not None:
898
896
trees = trees + tuple(extra_trees)
899
# target is usually the newer tree:
900
specific_file_ids = self.target.paths2ids(specific_files, trees,
901
require_versioned=require_versioned)
902
if specific_files and not specific_file_ids:
903
# All files are unversioned, so just return an empty delta
904
# _compare_trees would think we want a complete delta
905
result = delta.TreeDelta()
906
fake_entry = inventory.InventoryFile('unused', 'unused', 'unused')
907
result.unversioned = [(path, None,
908
self.target._comparison_data(fake_entry, path)[0]) for path in
911
return delta._compare_trees(self.source, self.target, want_unchanged,
912
specific_files, include_root, extra_trees=extra_trees,
913
require_versioned=require_versioned,
914
want_unversioned=want_unversioned)
897
with self.lock_read():
898
# target is usually the newer tree:
899
specific_file_ids = self.target.paths2ids(specific_files, trees,
900
require_versioned=require_versioned)
901
if specific_files and not specific_file_ids:
902
# All files are unversioned, so just return an empty delta
903
# _compare_trees would think we want a complete delta
904
result = delta.TreeDelta()
905
fake_entry = inventory.InventoryFile('unused', 'unused', 'unused')
906
result.unversioned = [(path, None,
907
self.target._comparison_data(fake_entry, path)[0]) for path in
910
return delta._compare_trees(self.source, self.target, want_unchanged,
911
specific_files, include_root, extra_trees=extra_trees,
912
require_versioned=require_versioned,
913
want_unversioned=want_unversioned)
916
915
def iter_changes(self, include_unchanged=False,
917
916
specific_files=None, pb=None, extra_trees=[],
1166
1165
changed_file_ids.add(result[0])
1170
def file_content_matches(self, source_file_id, target_file_id,
1171
source_path=None, target_path=None, source_stat=None, target_stat=None):
1168
def file_content_matches(
1169
self, source_file_id, target_file_id, source_path=None,
1170
target_path=None, source_stat=None, target_stat=None):
1172
1171
"""Check if two files are the same in the source and target trees.
1174
1173
This only checks that the contents of the files are the same,
1182
1181
:param target_stat: Optional stat value of the file in the target tree
1183
1182
:return: Boolean indicating whether the files have the same contents
1185
source_verifier_kind, source_verifier_data = self.source.get_file_verifier(
1186
source_file_id, source_path, source_stat)
1187
target_verifier_kind, target_verifier_data = self.target.get_file_verifier(
1188
target_file_id, target_path, target_stat)
1189
if source_verifier_kind == target_verifier_kind:
1190
return (source_verifier_data == target_verifier_data)
1191
# Fall back to SHA1 for now
1192
if source_verifier_kind != "SHA1":
1193
source_sha1 = self.source.get_file_sha1(source_file_id,
1194
source_path, source_stat)
1196
source_sha1 = source_verifier_data
1197
if target_verifier_kind != "SHA1":
1198
target_sha1 = self.target.get_file_sha1(target_file_id,
1199
target_path, target_stat)
1201
target_sha1 = target_verifier_data
1202
return (source_sha1 == target_sha1)
1184
with self.lock_read():
1185
source_verifier_kind, source_verifier_data = (
1186
self.source.get_file_verifier(
1187
source_file_id, source_path, source_stat))
1188
target_verifier_kind, target_verifier_data = (
1189
self.target.get_file_verifier(
1190
target_file_id, target_path, target_stat))
1191
if source_verifier_kind == target_verifier_kind:
1192
return (source_verifier_data == target_verifier_data)
1193
# Fall back to SHA1 for now
1194
if source_verifier_kind != "SHA1":
1195
source_sha1 = self.source.get_file_sha1(
1196
source_file_id, source_path, source_stat)
1198
source_sha1 = source_verifier_data
1199
if target_verifier_kind != "SHA1":
1200
target_sha1 = self.target.get_file_sha1(
1201
target_file_id, target_path, target_stat)
1203
target_sha1 = target_verifier_data
1204
return (source_sha1 == target_sha1)
1204
1206
InterTree.register_optimiser(InterTree)