~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-22 02:16:19 UTC
  • mfrom: (4180.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090322021619-onz77khivwa932zn
filtered deltas (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

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