~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-31 05:02:20 UTC
  • Revision ID: mbp@sourcefrog.net-20050331050220-0bd040ac11108caa
new "directories" command

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
            self.children = {}
129
129
 
130
130
 
 
131
    def sorted_children(self):
 
132
        l = self.children.items()
 
133
        l.sort()
 
134
        return l
 
135
 
 
136
 
131
137
    def copy(self):
132
138
        other = InventoryEntry(self.file_id, self.name, self.kind,
133
139
                               self.text_id, self.parent_id)
205
211
        self.children = {}
206
212
        self.kind = 'root_directory'
207
213
        self.parent_id = None
 
214
        self.name = ''
208
215
 
209
216
    def __cmp__(self, other):
210
217
        if self is other:
318
325
    def directories(self, from_dir=None):
319
326
        """Return (path, entry) pairs for all directories.
320
327
        """
321
 
        assert self.root
322
 
        yield '', self.root
323
 
        for path, entry in self.iter_entries():
324
 
            if entry.kind == 'directory':
325
 
                yield path, entry
 
328
        def descend(parent_ie):
 
329
            parent_name = parent_ie.name
 
330
            if parent_name == '':
 
331
                parent_name = '.'
 
332
            yield parent_name, parent_ie
 
333
 
 
334
            # directory children in sorted order
 
335
            dn = []
 
336
            for ie in parent_ie.children.itervalues():
 
337
                if ie.kind == 'directory':
 
338
                    dn.append((ie.name, ie))
 
339
            dn.sort()
 
340
            
 
341
            for name, child_ie in dn:
 
342
                for sub_name, sub_ie in descend(child_ie):
 
343
                    yield appendpath(parent_name, sub_name), sub_ie
 
344
 
 
345
        for name, ie in descend(self.root):
 
346
            yield name, ie
326
347
        
327
348
 
328
349