/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Robert Collins
  • Date: 2006-06-09 07:49:24 UTC
  • mfrom: (1753.1.4 add)
  • mto: (1725.2.9 commit)
  • mto: This revision was merged to the branch mainline in revision 1756.
  • Revision ID: robertc@robertcollins.net-20060609074924-82f9c095a195cbcc
(jam, robertc, ab)Merge new iter_entries_by_dirs routine which matches the order walkdirs provides.

Show diffs side-by-side

added added

removed removed

Lines of Context:
706
706
        if self.text_sha1 != None or self.text_size != None or self.text_id != None:
707
707
            raise BzrCheckError('symlink {%s} has text in revision {%s}'
708
708
                    % (self.file_id, rev_id))
709
 
        if self.symlink_target == None:
 
709
        if self.symlink_target is None:
710
710
            raise BzrCheckError('symlink {%s} has no target in revision {%s}'
711
711
                    % (self.file_id, rev_id))
712
712
 
866
866
 
867
867
    def iter_entries(self, from_dir=None):
868
868
        """Return (path, entry) pairs, in order by name."""
869
 
        if from_dir == None:
 
869
        if from_dir is None:
870
870
            assert self.root
871
871
            from_dir = self.root
872
872
        elif isinstance(from_dir, basestring):
906
906
                # if we finished all children, pop it off the stack
907
907
                stack.pop()
908
908
 
 
909
    def iter_entries_by_dir(self, from_dir=None):
 
910
        """Iterate over the entries in a directory first order.
 
911
 
 
912
        This returns all entries for a directory before returning
 
913
        the entries for children of a directory. This is not
 
914
        lexicographically sorted order, and is a hybrid between
 
915
        depth-first and breadth-first.
 
916
 
 
917
        :return: This yields (path, entry) pairs
 
918
        """
 
919
        # TODO? Perhaps this should return the from_dir so that the root is
 
920
        # yielded? or maybe an option?
 
921
        if from_dir is None:
 
922
            assert self.root
 
923
            from_dir = self.root
 
924
        elif isinstance(from_dir, basestring):
 
925
            from_dir = self._byid[from_dir]
 
926
            
 
927
        stack = [(u'', from_dir)]
 
928
        while stack:
 
929
            cur_relpath, cur_dir = stack.pop()
 
930
 
 
931
            child_dirs = []
 
932
            for child_name, child_ie in sorted(cur_dir.children.iteritems()):
 
933
 
 
934
                child_relpath = cur_relpath + child_name
 
935
 
 
936
                yield child_relpath, child_ie
 
937
 
 
938
                if child_ie.kind == 'directory':
 
939
                    child_dirs.append((child_relpath+'/', child_ie))
 
940
            stack.extend(reversed(child_dirs))
 
941
 
909
942
    def entries(self):
910
943
        """Return list of (path, ie) for all entries except the root.
911
944
 
969
1002
        try:
970
1003
            return self._byid[file_id]
971
1004
        except KeyError:
972
 
            if file_id == None:
 
1005
            if file_id is None:
973
1006
                raise BzrError("can't look up file_id None")
974
1007
            else:
975
1008
                raise BzrError("file_id {%s} not in inventory" % file_id)
1028
1061
        else:
1029
1062
            parent_path = parts[:-1]
1030
1063
            parent_id = self.path2id(parent_path)
1031
 
            if parent_id == None:
 
1064
            if parent_id is None:
1032
1065
                raise NotVersionedError(path=parent_path)
1033
1066
        ie = make_entry(kind, parts[-1], parent_id, file_id)
1034
1067
        return self.add(ie)
1218
1251
 
1219
1252
def is_valid_name(name):
1220
1253
    global _NAME_RE
1221
 
    if _NAME_RE == None:
 
1254
    if _NAME_RE is None:
1222
1255
        _NAME_RE = re.compile(r'^[^/\\]+$')
1223
1256
        
1224
1257
    return bool(_NAME_RE.match(name))