~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Ian Clatworthy
  • Date: 2009-03-13 00:29:41 UTC
  • mto: (4180.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 4181.
  • Revision ID: ian.clatworthy@canonical.com-20090313002941-0y35d4gxh0ck3pdc
Inventory.filter() API with tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1339
1339
    def is_root(self, file_id):
1340
1340
        return self.root is not None and file_id == self.root.file_id
1341
1341
 
 
1342
    def filter(self, specific_fileids):
 
1343
        """Copy an inventory filtering against a set of file-ids.
 
1344
 
 
1345
        Children of directories and parents are included.
 
1346
        """
 
1347
        interesting_parents = set()
 
1348
        for fileid in specific_fileids:
 
1349
            try:
 
1350
                interesting_parents.update(self.get_idpath(fileid))
 
1351
            except errors.NoSuchId:
 
1352
                # This fileid is not in the inventory - that's ok
 
1353
                pass
 
1354
        entries = self.iter_entries()
 
1355
        if self.root is None:
 
1356
            return Inventory(root_id=None)
 
1357
        other = Inventory(entries.next()[1].file_id)
 
1358
        other.root.revision = self.root.revision
 
1359
        other.revision_id = self.revision_id
 
1360
        directories_to_expand = set()
 
1361
        for path, entry in entries:
 
1362
            file_id = entry.file_id
 
1363
            if (file_id in specific_fileids
 
1364
                or entry.parent_id in directories_to_expand):
 
1365
                if entry.kind == 'directory':
 
1366
                    directories_to_expand.add(file_id)
 
1367
            elif file_id not in interesting_parents:
 
1368
                continue
 
1369
            other.add(entry.copy())
 
1370
        return other
 
1371
 
1342
1372
 
1343
1373
entry_factory = {
1344
1374
    'directory': InventoryDirectory,