def _unpack_inventory(self, elt, revision_id, entry_cache=None, return_from_cache=False): """Construct from XML Element """ root_id = elt.get('file_id') or inventory.ROOT_ID root_id = get_utf8_or_ascii(root_id) format = elt.get('format') if format is not None: if format != '5': raise errors.BzrError("invalid format version %r on inventory" % format) data_revision_id = elt.get('revision_id') if data_revision_id is not None: revision_id = cache_utf8.encode(data_revision_id) inv = inventory.Inventory(root_id, revision_id=revision_id) # Optimizations tested # baseline w/entry cache 2.85s # using inv._byid 2.55s # avoiding attributes 2.46s # adding assertions 2.50s # last_parent cache 2.52s (worse, removed) byid = inv._byid for e in elt: ie = unpack_inventory_entry(e, entry_cache=entry_cache, return_from_cache=return_from_cache) parent_id = ie.parent_id if parent_id is None: ie.parent_id = parent_id = root_id try: parent = byid[parent_id] except KeyError: raise errors.BzrError("parent_id {%s} not in inventory" % (parent_id,)) if ie.file_id in byid: raise errors.DuplicateFileId(ie.file_id, byid[ie.file_id]) if ie.name in parent.children: raise errors.BzrError("%s is already versioned" % (osutils.pathjoin(inv.id2path(parent_id), ie.name).encode('utf-8'),)) parent.children[ie.name] = ie byid[ie.file_id] = ie if revision_id is not None: inv.root.revision = revision_id self._check_cache_size(len(inv), entry_cache) return inv
def _unpack_entry(self, elt, entry_cache=None, return_from_cache=False): # This is here because it's overridden by xml7 return unpack_inventory_entry(elt, entry_cache, return_from_cache)