~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-16 11:08:11 UTC
  • mfrom: (6521 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6522.
  • Revision ID: jelmer@samba.org-20120416110811-0y996ihqy9o2bb1t
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
633
633
    inserted, other than through the Inventory API.
634
634
    """
635
635
 
636
 
    @deprecated_method(deprecated_in((2, 4, 0)))
637
 
    def __contains__(self, file_id):
638
 
        """True if this entry contains a file with given id.
639
 
 
640
 
        >>> inv = Inventory()
641
 
        >>> inv.add(InventoryFile('123', 'foo.c', ROOT_ID))
642
 
        InventoryFile('123', 'foo.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
643
 
        >>> inv.has_id('123')
644
 
        True
645
 
        >>> inv.has_id('456')
646
 
        False
647
 
 
648
 
        Note that this method along with __iter__ are not encouraged for use as
649
 
        they are less clear than specific query methods - they may be rmeoved
650
 
        in the future.
651
 
        """
652
 
        return self.has_id(file_id)
653
 
 
654
636
    def has_filename(self, filename):
655
637
        return bool(self.path2id(filename))
656
638
 
850
832
            descend(self.root, u'')
851
833
        return accum
852
834
 
853
 
    def directories(self):
854
 
        """Return (path, entry) pairs for all directories, including the root.
855
 
        """
856
 
        accum = []
857
 
        def descend(parent_ie, parent_path):
858
 
            accum.append((parent_path, parent_ie))
859
 
 
860
 
            kids = [(ie.name, ie) for ie in parent_ie.children.itervalues() if ie.kind == 'directory']
861
 
            kids.sort()
862
 
 
863
 
            for name, child_ie in kids:
864
 
                child_path = osutils.pathjoin(parent_path, name)
865
 
                descend(child_ie, child_path)
866
 
        descend(self.root, u'')
867
 
        return accum
868
 
 
869
835
    def path2id(self, relpath):
870
836
        """Walk down through directories to return entry of last component.
871
837
 
2127
2093
    def path2id(self, relpath):
2128
2094
        """See CommonInventory.path2id()."""
2129
2095
        # TODO: perhaps support negative hits?
 
2096
        if isinstance(relpath, basestring):
 
2097
            names = osutils.splitpath(relpath)
 
2098
        else:
 
2099
            names = relpath
 
2100
            if relpath == []:
 
2101
                relpath = [""]
 
2102
            relpath = osutils.pathjoin(*relpath)
2130
2103
        result = self._path_to_fileid_cache.get(relpath, None)
2131
2104
        if result is not None:
2132
2105
            return result
2133
 
        if isinstance(relpath, basestring):
2134
 
            names = osutils.splitpath(relpath)
2135
 
        else:
2136
 
            names = relpath
2137
2106
        current_id = self.root_id
2138
2107
        if current_id is None:
2139
2108
            return None