~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-14 16:54:26 UTC
  • mfrom: (6216.1.1 remove-this-file)
  • Revision ID: pqm@pqm.ubuntu.com-20111014165426-tjix4e6idryf1r2z
(jelmer) Remove an accidentally committed .THIS file. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    rules,
36
36
    trace,
37
37
    )
 
38
from bzrlib.i18n import gettext
38
39
""")
39
40
 
40
41
from bzrlib.decorators import needs_read_lock
58
59
    trees or versioned trees.
59
60
    """
60
61
 
 
62
    def has_versioned_directories(self):
 
63
        """Whether this tree can contain explicitly versioned directories.
 
64
 
 
65
        This defaults to True, but some implementations may want to override
 
66
        it.
 
67
        """
 
68
        return True
 
69
 
61
70
    def changes_from(self, other, want_unchanged=False, specific_files=None,
62
71
        extra_trees=None, require_versioned=False, include_root=False,
63
72
        want_unversioned=False):
127
136
    def has_id(self, file_id):
128
137
        raise NotImplementedError(self.has_id)
129
138
 
 
139
    @deprecated_method(deprecated_in((2, 4, 0)))
130
140
    def __contains__(self, file_id):
131
141
        return self.has_id(file_id)
132
142
 
276
286
 
277
287
        :param file_id: The file_id of the file.
278
288
        :param path: The path of the file.
 
289
 
279
290
        If both file_id and path are supplied, an implementation may use
280
291
        either one.
 
292
 
 
293
        :returns: A single byte string for the whole file.
281
294
        """
282
295
        my_file = self.get_file(file_id, path)
283
296
        try:
296
309
        """
297
310
        return osutils.split_lines(self.get_file_text(file_id, path))
298
311
 
 
312
    def get_file_verifier(self, file_id, path=None, stat_value=None):
 
313
        """Return a verifier for a file.
 
314
 
 
315
        The default implementation returns a sha1.
 
316
 
 
317
        :param file_id: The handle for this file.
 
318
        :param path: The path that this file can be found at.
 
319
            These must point to the same object.
 
320
        :param stat_value: Optional stat value for the object
 
321
        :return: Tuple with verifier name and verifier data
 
322
        """
 
323
        return ("SHA1", self.get_file_sha1(file_id, path=path,
 
324
            stat_value=stat_value))
 
325
 
299
326
    def get_file_sha1(self, file_id, path=None, stat_value=None):
300
327
        """Return the SHA1 file for a file.
301
328
 
 
329
        :note: callers should use get_file_verifier instead
 
330
            where possible, as the underlying repository implementation may
 
331
            have quicker access to a non-sha1 verifier.
 
332
 
302
333
        :param file_id: The handle for this file.
303
334
        :param path: The path that this file can be found at.
304
335
            These must point to the same object.
601
632
        prefs = self.iter_search_rules([path], filter_pref_names).next()
602
633
        stk = filters._get_filter_stack_for(prefs)
603
634
        if 'filters' in debug.debug_flags:
604
 
            trace.note("*** %s content-filter: %s => %r" % (path,prefs,stk))
 
635
            trace.note(gettext("*** {0} content-filter: {1} => {2!r}").format(path,prefs,stk))
605
636
        return stk
606
637
 
607
638
    def _content_filter_stack_provider(self):
951
982
        if source_kind != target_kind:
952
983
            changed_content = True
953
984
        elif source_kind == 'file':
954
 
            if (self.source.get_file_sha1(file_id, source_path, source_stat) !=
955
 
                self.target.get_file_sha1(file_id, target_path, target_stat)):
 
985
            if not self.file_content_matches(file_id, file_id, source_path,
 
986
                    target_path, source_stat, target_stat):
956
987
                changed_content = True
957
988
        elif source_kind == 'symlink':
958
989
            if (self.source.get_symlink_target(file_id) !=
1271
1302
                    changed_file_ids.add(result[0])
1272
1303
                    yield result
1273
1304
 
 
1305
    @needs_read_lock
 
1306
    def file_content_matches(self, source_file_id, target_file_id,
 
1307
            source_path=None, target_path=None, source_stat=None, target_stat=None):
 
1308
        """Check if two files are the same in the source and target trees.
 
1309
 
 
1310
        This only checks that the contents of the files are the same,
 
1311
        it does not touch anything else.
 
1312
 
 
1313
        :param source_file_id: File id of the file in the source tree
 
1314
        :param target_file_id: File id of the file in the target tree
 
1315
        :param source_path: Path of the file in the source tree
 
1316
        :param target_path: Path of the file in the target tree
 
1317
        :param source_stat: Optional stat value of the file in the source tree
 
1318
        :param target_stat: Optional stat value of the file in the target tree
 
1319
        :return: Boolean indicating whether the files have the same contents
 
1320
        """
 
1321
        source_verifier_kind, source_verifier_data = self.source.get_file_verifier(
 
1322
            source_file_id, source_path, source_stat)
 
1323
        target_verifier_kind, target_verifier_data = self.target.get_file_verifier(
 
1324
            target_file_id, target_path, target_stat)
 
1325
        if source_verifier_kind == target_verifier_kind:
 
1326
            return (source_verifier_data == target_verifier_data)
 
1327
        # Fall back to SHA1 for now
 
1328
        if source_verifier_kind != "SHA1":
 
1329
            source_sha1 = self.source.get_file_sha1(source_file_id,
 
1330
                    source_path, source_stat)
 
1331
        else:
 
1332
            source_sha1 = source_verifier_data
 
1333
        if target_verifier_kind != "SHA1":
 
1334
            target_sha1 = self.target.get_file_sha1(target_file_id,
 
1335
                    target_path, target_stat)
 
1336
        else:
 
1337
            target_sha1 = target_verifier_data
 
1338
        return (source_sha1 == target_sha1)
1274
1339
 
1275
1340
InterTree.register_optimiser(InterTree)
1276
1341