/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tree.py

  • Committer: Jelmer Vernooij
  • Date: 2017-09-06 04:15:55 UTC
  • mfrom: (6754.8.21 lock-context-2)
  • Revision ID: jelmer@jelmer.uk-20170906041555-jtr5qxli38167gc6
Merge lp:~jelmer/brz/lock-context-2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    lock,
46
46
    osutils,
47
47
    )
48
 
from .decorators import needs_read_lock
49
48
from .inter import InterObject
50
49
from .sixish import (
51
50
    viewvalues,
873
872
        return (file_id, (source_path, target_path), changed_content,
874
873
                versioned, parent, name, kind, executable), changes
875
874
 
876
 
    @needs_read_lock
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
909
 
                specific_files]
910
 
            return result
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
 
908
                    specific_files]
 
909
                return result
 
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)
915
914
 
916
915
    def iter_changes(self, include_unchanged=False,
917
916
                      specific_files=None, pb=None, extra_trees=[],
1155
1154
                precise_file_ids.add(new_parent_id)
1156
1155
                if changes:
1157
1156
                    if (result[6][0] == 'directory' and
1158
 
                        result[6][1] != 'directory'):
 
1157
                            result[6][1] != 'directory'):
1159
1158
                        # This stopped being a directory, the old children have
1160
1159
                        # to be included.
1161
1160
                        if old_entry is None:
1166
1165
                    changed_file_ids.add(result[0])
1167
1166
                    yield result
1168
1167
 
1169
 
    @needs_read_lock
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.
1173
1172
 
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
1184
1183
        """
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)
1195
 
        else:
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)
1200
 
        else:
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)
 
1197
            else:
 
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)
 
1202
            else:
 
1203
                target_sha1 = target_verifier_data
 
1204
            return (source_sha1 == target_sha1)
1203
1205
 
1204
1206
InterTree.register_optimiser(InterTree)
1205
1207