357
357
ie = self._unpack_entry(e)
359
if len(inv) > _entry_cache._max_cache:
360
new_len = len(inv) * 1.2
361
trace.note('Resizing inventory cache to %s', new_len)
362
_entry_cache.resize(new_len)
365
361
def _unpack_entry(self, elt):
362
get_cached = _get_utf8_or_ascii
365
file_id = elt_get('file_id')
366
revision = elt_get('revision')
367
# Check and see if we have already unpacked this exact entry
368
key = (file_id, revision)
370
# We copy it, because some operatations may mutate it
371
return _entry_cache[key].copy()
367
376
if not InventoryEntry.versionable_kind(kind):
368
377
raise AssertionError('unsupported entry kind %s' % kind)
370
get_cached = _get_utf8_or_ascii
372
file_id = elt.get('file_id')
373
revision = elt.get('revision')
374
# Check and see if we have already unpacked this exact entry
375
key = (file_id, revision)
376
cached_ie = _entry_cache.get(key, None)
377
if cached_ie is not None:
378
# We copy it, because some operatations may mutate it
379
return cached_ie.copy()
381
379
file_id = get_cached(file_id)
382
380
if revision is not None:
383
381
revision = get_cached(revision)
384
parent_id = elt.get('parent_id')
382
parent_id = elt_get('parent_id')
385
383
if parent_id is not None:
386
384
parent_id = get_cached(parent_id)
388
386
if kind == 'directory':
389
387
ie = inventory.InventoryDirectory(file_id,
392
390
elif kind == 'file':
393
391
ie = inventory.InventoryFile(file_id,
396
ie.text_sha1 = elt.get('text_sha1')
397
if elt.get('executable') == 'yes':
394
ie.text_sha1 = elt_get('text_sha1')
395
if elt_get('executable') == 'yes':
398
396
ie.executable = True
399
v = elt.get('text_size')
397
v = elt_get('text_size')
400
398
ie.text_size = v and int(v)
401
399
elif kind == 'symlink':
402
400
ie = inventory.InventoryLink(file_id,
405
ie.symlink_target = elt.get('symlink_target')
403
ie.symlink_target = elt_get('symlink_target')
407
405
raise errors.UnsupportedInventoryKind(kind)
408
406
ie.revision = revision