~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Martin von Gagern
  • Date: 2011-06-01 12:53:56 UTC
  • mto: This revision was merged to the branch mainline in revision 6009.
  • Revision ID: martin.vgagern@gmx.net-20110601125356-lwozv2vecea6hxfz
Change from no_decorate to classify as name for the argument.

The command line switch remains as --no-classify, to keep backwards
compatibility.  Users are free to include --no-classify in an alias, and
still use --classify to change back.

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
39
38
""")
40
39
 
41
40
from bzrlib.decorators import needs_read_lock
59
58
    trees or versioned trees.
60
59
    """
61
60
 
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
 
 
70
61
    def changes_from(self, other, want_unchanged=False, specific_files=None,
71
62
        extra_trees=None, require_versioned=False, include_root=False,
72
63
        want_unversioned=False):
136
127
    def has_id(self, file_id):
137
128
        raise NotImplementedError(self.has_id)
138
129
 
139
 
    @deprecated_method(deprecated_in((2, 4, 0)))
140
130
    def __contains__(self, file_id):
141
131
        return self.has_id(file_id)
142
132
 
286
276
 
287
277
        :param file_id: The file_id of the file.
288
278
        :param path: The path of the file.
289
 
 
290
279
        If both file_id and path are supplied, an implementation may use
291
280
        either one.
292
 
 
293
 
        :returns: A single byte string for the whole file.
294
281
        """
295
282
        my_file = self.get_file(file_id, path)
296
283
        try:
309
296
        """
310
297
        return osutils.split_lines(self.get_file_text(file_id, path))
311
298
 
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
 
 
326
299
    def get_file_sha1(self, file_id, path=None, stat_value=None):
327
300
        """Return the SHA1 file for a file.
328
301
 
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
 
 
333
302
        :param file_id: The handle for this file.
334
303
        :param path: The path that this file can be found at.
335
304
            These must point to the same object.
632
601
        prefs = self.iter_search_rules([path], filter_pref_names).next()
633
602
        stk = filters._get_filter_stack_for(prefs)
634
603
        if 'filters' in debug.debug_flags:
635
 
            trace.note(gettext("*** {0} content-filter: {1} => {2!r}").format(path,prefs,stk))
 
604
            trace.note("*** %s content-filter: %s => %r" % (path,prefs,stk))
636
605
        return stk
637
606
 
638
607
    def _content_filter_stack_provider(self):
831
800
        return self.get_file(self._inventory.path2id(path), path)
832
801
 
833
802
 
 
803
######################################################################
 
804
# diff
 
805
 
 
806
# TODO: Merge these two functions into a single one that can operate
 
807
# on either a whole tree or a set of files.
 
808
 
 
809
# TODO: Return the diff in order by filename, not by category or in
 
810
# random order.  Can probably be done by lock-stepping through the
 
811
# filenames from both trees.
 
812
 
 
813
 
 
814
def file_status(filename, old_tree, new_tree):
 
815
    """Return single-letter status, old and new names for a file.
 
816
 
 
817
    The complexity here is in deciding how to represent renames;
 
818
    many complex cases are possible.
 
819
    """
 
820
    old_inv = old_tree.inventory
 
821
    new_inv = new_tree.inventory
 
822
    new_id = new_inv.path2id(filename)
 
823
    old_id = old_inv.path2id(filename)
 
824
 
 
825
    if not new_id and not old_id:
 
826
        # easy: doesn't exist in either; not versioned at all
 
827
        if new_tree.is_ignored(filename):
 
828
            return 'I', None, None
 
829
        else:
 
830
            return '?', None, None
 
831
    elif new_id:
 
832
        # There is now a file of this name, great.
 
833
        pass
 
834
    else:
 
835
        # There is no longer a file of this name, but we can describe
 
836
        # what happened to the file that used to have
 
837
        # this name.  There are two possibilities: either it was
 
838
        # deleted entirely, or renamed.
 
839
        if new_inv.has_id(old_id):
 
840
            return 'X', old_inv.id2path(old_id), new_inv.id2path(old_id)
 
841
        else:
 
842
            return 'D', old_inv.id2path(old_id), None
 
843
 
 
844
    # if the file_id is new in this revision, it is added
 
845
    if new_id and not old_inv.has_id(new_id):
 
846
        return 'A'
 
847
 
 
848
    # if there used to be a file of this name, but that ID has now
 
849
    # disappeared, it is deleted
 
850
    if old_id and not new_inv.has_id(old_id):
 
851
        return 'D'
 
852
 
 
853
    return 'wtf?'
 
854
 
 
855
 
834
856
def find_ids_across_trees(filenames, trees, require_versioned=True):
835
857
    """Find the ids corresponding to specified filenames.
836
858
 
982
1004
        if source_kind != target_kind:
983
1005
            changed_content = True
984
1006
        elif source_kind == 'file':
985
 
            if not self.file_content_matches(file_id, file_id, source_path,
986
 
                    target_path, source_stat, target_stat):
 
1007
            if (self.source.get_file_sha1(file_id, source_path, source_stat) !=
 
1008
                self.target.get_file_sha1(file_id, target_path, target_stat)):
987
1009
                changed_content = True
988
1010
        elif source_kind == 'symlink':
989
1011
            if (self.source.get_symlink_target(file_id) !=
1302
1324
                    changed_file_ids.add(result[0])
1303
1325
                    yield result
1304
1326
 
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)
1339
1327
 
1340
1328
InterTree.register_optimiser(InterTree)
1341
1329