~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-04 17:38:09 UTC
  • mfrom: (5805.1.1 no-inventory)
  • Revision ID: pqm@pqm.ubuntu.com-20110504173809-otz0gw0cvf2z9jbk
(jelmer) Avoid using inventories in some repository tests. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
from bzrlib.decorators import needs_read_lock
41
41
from bzrlib.inter import InterObject
42
 
from bzrlib.symbol_versioning import (
43
 
    deprecated_in,
44
 
    deprecated_method,
45
 
    )
46
42
 
47
43
 
48
44
class Tree(object):
127
123
    def has_id(self, file_id):
128
124
        raise NotImplementedError(self.has_id)
129
125
 
130
 
    @deprecated_method(deprecated_in((2, 4, 0)))
131
126
    def __contains__(self, file_id):
132
127
        return self.has_id(file_id)
133
128
 
142
137
        """
143
138
        return False
144
139
 
 
140
    def __iter__(self):
 
141
        """Yield all file ids in this tree."""
 
142
        raise NotImplementedError(self.__iter__)
 
143
 
145
144
    def all_file_ids(self):
146
145
        """Iterate through all file ids, including ids for missing files."""
147
 
        raise NotImplementedError(self.all_file_ids)
 
146
        return set(self.inventory)
148
147
 
149
148
    def id2path(self, file_id):
150
149
        """Return the path for a file id.
175
174
             g
176
175
 
177
176
        The yield order (ignoring root) would be::
178
 
 
179
177
          a, f, a/b, a/d, a/b/c, a/d/e, f/g
180
178
 
181
179
        :param yield_parents: If True, yield the parents from the root leading
291
289
 
292
290
        :param file_id: The file_id of the file.
293
291
        :param path: The path of the file.
294
 
 
295
292
        If both file_id and path are supplied, an implementation may use
296
293
        either one.
297
294
        """
298
295
        return osutils.split_lines(self.get_file_text(file_id, path))
299
296
 
300
 
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
297
    def get_file_sha1(self, file_id, path=None):
301
298
        """Return the SHA1 file for a file.
302
299
 
303
300
        :param file_id: The handle for this file.
304
301
        :param path: The path that this file can be found at.
305
302
            These must point to the same object.
306
 
        :param stat_value: Optional stat value for the object
307
303
        """
308
304
        raise NotImplementedError(self.get_file_sha1)
309
305
 
363
359
            cur_file = (self.get_file_text(file_id),)
364
360
            yield identifier, cur_file
365
361
 
366
 
    def get_symlink_target(self, file_id, path=None):
 
362
    def get_symlink_target(self, file_id):
367
363
        """Get the target for a given file_id.
368
364
 
369
365
        It is assumed that the caller already knows that file_id is referencing
370
366
        a symlink.
371
367
        :param file_id: Handle for the symlink entry.
372
 
        :param path: The path of the file.
373
 
        If both file_id and path are supplied, an implementation may use
374
 
        either one.
375
368
        :return: The path the symlink points to.
376
369
        """
377
370
        raise NotImplementedError(self.get_symlink_target)
378
371
 
 
372
 
379
373
    def get_root_id(self):
380
374
        """Return the file_id for the root of this tree."""
381
375
        raise NotImplementedError(self.get_root_id)
763
757
    def has_or_had_id(self, file_id):
764
758
        return self.inventory.has_id(file_id)
765
759
 
766
 
    def all_file_ids(self):
767
 
        return set(self.inventory)
768
 
 
769
 
    @deprecated_method(deprecated_in((2, 4, 0)))
770
760
    def __iter__(self):
771
761
        return iter(self.inventory)
772
762
 
801
791
        return self.get_file(self._inventory.path2id(path), path)
802
792
 
803
793
 
 
794
######################################################################
 
795
# diff
 
796
 
 
797
# TODO: Merge these two functions into a single one that can operate
 
798
# on either a whole tree or a set of files.
 
799
 
 
800
# TODO: Return the diff in order by filename, not by category or in
 
801
# random order.  Can probably be done by lock-stepping through the
 
802
# filenames from both trees.
 
803
 
 
804
 
 
805
def file_status(filename, old_tree, new_tree):
 
806
    """Return single-letter status, old and new names for a file.
 
807
 
 
808
    The complexity here is in deciding how to represent renames;
 
809
    many complex cases are possible.
 
810
    """
 
811
    old_inv = old_tree.inventory
 
812
    new_inv = new_tree.inventory
 
813
    new_id = new_inv.path2id(filename)
 
814
    old_id = old_inv.path2id(filename)
 
815
 
 
816
    if not new_id and not old_id:
 
817
        # easy: doesn't exist in either; not versioned at all
 
818
        if new_tree.is_ignored(filename):
 
819
            return 'I', None, None
 
820
        else:
 
821
            return '?', None, None
 
822
    elif new_id:
 
823
        # There is now a file of this name, great.
 
824
        pass
 
825
    else:
 
826
        # There is no longer a file of this name, but we can describe
 
827
        # what happened to the file that used to have
 
828
        # this name.  There are two possibilities: either it was
 
829
        # deleted entirely, or renamed.
 
830
        if new_inv.has_id(old_id):
 
831
            return 'X', old_inv.id2path(old_id), new_inv.id2path(old_id)
 
832
        else:
 
833
            return 'D', old_inv.id2path(old_id), None
 
834
 
 
835
    # if the file_id is new in this revision, it is added
 
836
    if new_id and not old_inv.has_id(new_id):
 
837
        return 'A'
 
838
 
 
839
    # if there used to be a file of this name, but that ID has now
 
840
    # disappeared, it is deleted
 
841
    if old_id and not new_inv.has_id(old_id):
 
842
        return 'D'
 
843
 
 
844
    return 'wtf?'
 
845
 
 
846
 
804
847
def find_ids_across_trees(filenames, trees, require_versioned=True):
805
848
    """Find the ids corresponding to specified filenames.
806
849
 
811
854
        None)
812
855
    :param trees: The trees to find file_ids within
813
856
    :param require_versioned: if true, all specified filenames must occur in
814
 
        at least one tree.
 
857
    at least one tree.
815
858
    :return: a set of file ids for the specified filenames and their children.
816
859
    """
817
860
    if not filenames:
893
936
 
894
937
    _optimisers = []
895
938
 
896
 
    @classmethod
897
 
    def is_compatible(kls, source, target):
898
 
        # The default implementation is naive and uses the public API, so
899
 
        # it works for all trees.
900
 
        return True
901
 
 
902
939
    def _changes_from_entries(self, source_entry, target_entry,
903
940
        source_path=None, target_path=None):
904
941
        """Generate a iter_changes tuple between source_entry and target_entry.
1273
1310
                    yield result
1274
1311
 
1275
1312
 
1276
 
InterTree.register_optimiser(InterTree)
1277
 
 
1278
 
 
1279
1313
class MultiWalker(object):
1280
1314
    """Walk multiple trees simultaneously, getting combined results."""
1281
1315