~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Ross Lagerwall
  • Date: 2012-08-07 06:32:51 UTC
  • mto: (6437.63.5 2.5)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: rosslagerwall@gmail.com-20120807063251-x9p03ghg2ws8oqjc
Add bzrlib/locale to .bzrignore

bzrlib/locale is generated with ./setup.py build_mo which is in turn called
by ./setup.py build

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
 
636
654
    def has_filename(self, filename):
637
655
        return bool(self.path2id(filename))
638
656
 
832
850
            descend(self.root, u'')
833
851
        return accum
834
852
 
 
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
 
835
869
    def path2id(self, relpath):
836
870
        """Walk down through directories to return entry of last component.
837
871
 
2093
2127
    def path2id(self, relpath):
2094
2128
        """See CommonInventory.path2id()."""
2095
2129
        # 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)
2103
2130
        result = self._path_to_fileid_cache.get(relpath, None)
2104
2131
        if result is not None:
2105
2132
            return result
 
2133
        if isinstance(relpath, basestring):
 
2134
            names = osutils.splitpath(relpath)
 
2135
        else:
 
2136
            names = relpath
2106
2137
        current_id = self.root_id
2107
2138
        if current_id is None:
2108
2139
            return None