~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-31 15:43:17 UTC
  • mfrom: (6437.3.28 2.5)
  • mto: (6437.23.1 2.5)
  • mto: This revision was merged to the branch mainline in revision 6458.
  • Revision ID: jelmer@samba.org-20120131154317-y028tz0r9xesvn9p
MergeĀ 2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tree classes, representing directory at point in time.
18
18
"""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import os
21
23
 
22
24
from bzrlib.lazy_import import lazy_import
35
37
    rules,
36
38
    trace,
37
39
    )
 
40
from bzrlib.i18n import gettext
38
41
""")
39
42
 
40
43
from bzrlib.decorators import needs_read_lock
58
61
    trees or versioned trees.
59
62
    """
60
63
 
 
64
    def has_versioned_directories(self):
 
65
        """Whether this tree can contain explicitly versioned directories.
 
66
 
 
67
        This defaults to True, but some implementations may want to override
 
68
        it.
 
69
        """
 
70
        return True
 
71
 
61
72
    def changes_from(self, other, want_unchanged=False, specific_files=None,
62
73
        extra_trees=None, require_versioned=False, include_root=False,
63
74
        want_unversioned=False):
277
288
 
278
289
        :param file_id: The file_id of the file.
279
290
        :param path: The path of the file.
 
291
 
280
292
        If both file_id and path are supplied, an implementation may use
281
293
        either one.
 
294
 
 
295
        :returns: A single byte string for the whole file.
282
296
        """
283
297
        my_file = self.get_file(file_id, path)
284
298
        try:
297
311
        """
298
312
        return osutils.split_lines(self.get_file_text(file_id, path))
299
313
 
 
314
    def get_file_verifier(self, file_id, path=None, stat_value=None):
 
315
        """Return a verifier for a file.
 
316
 
 
317
        The default implementation returns a sha1.
 
318
 
 
319
        :param file_id: The handle for this file.
 
320
        :param path: The path that this file can be found at.
 
321
            These must point to the same object.
 
322
        :param stat_value: Optional stat value for the object
 
323
        :return: Tuple with verifier name and verifier data
 
324
        """
 
325
        return ("SHA1", self.get_file_sha1(file_id, path=path,
 
326
            stat_value=stat_value))
 
327
 
300
328
    def get_file_sha1(self, file_id, path=None, stat_value=None):
301
329
        """Return the SHA1 file for a file.
302
330
 
 
331
        :note: callers should use get_file_verifier instead
 
332
            where possible, as the underlying repository implementation may
 
333
            have quicker access to a non-sha1 verifier.
 
334
 
303
335
        :param file_id: The handle for this file.
304
336
        :param path: The path that this file can be found at.
305
337
            These must point to the same object.
325
357
        """
326
358
        raise NotImplementedError(self.get_file_size)
327
359
 
328
 
    def get_file_by_path(self, path):
329
 
        raise NotImplementedError(self.get_file_by_path)
330
 
 
331
360
    def is_executable(self, file_id, path=None):
332
361
        """Check if a file is executable.
333
362
 
602
631
        prefs = self.iter_search_rules([path], filter_pref_names).next()
603
632
        stk = filters._get_filter_stack_for(prefs)
604
633
        if 'filters' in debug.debug_flags:
605
 
            trace.note("*** %s content-filter: %s => %r" % (path,prefs,stk))
 
634
            trace.note(gettext("*** {0} content-filter: {1} => {2!r}").format(path,prefs,stk))
606
635
        return stk
607
636
 
608
637
    def _content_filter_stack_provider(self):
797
826
        return self.inventory.iter_entries_by_dir(
798
827
            specific_file_ids=specific_file_ids, yield_parents=yield_parents)
799
828
 
 
829
    @deprecated_method(deprecated_in((2, 5, 0)))
800
830
    def get_file_by_path(self, path):
801
 
        return self.get_file(self._inventory.path2id(path), path)
 
831
        return self.get_file(self.path2id(path), path)
802
832
 
803
833
 
804
834
def find_ids_across_trees(filenames, trees, require_versioned=True):
952
982
        if source_kind != target_kind:
953
983
            changed_content = True
954
984
        elif source_kind == 'file':
955
 
            if (self.source.get_file_sha1(file_id, source_path, source_stat) !=
956
 
                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):
957
987
                changed_content = True
958
988
        elif source_kind == 'symlink':
959
989
            if (self.source.get_symlink_target(file_id) !=
1272
1302
                    changed_file_ids.add(result[0])
1273
1303
                    yield result
1274
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)
1275
1339
 
1276
1340
InterTree.register_optimiser(InterTree)
1277
1341