Skip to content
Snippets Groups Projects
Verified Commit 87fcced4 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Add objects_per_type api

This permits to reuse the same logic for different clients (loader-dir,
loader-tar, loader-svn)

(Tests were lost)
parent 17f04939
No related branches found
Tags v0.0.10
No related merge requests found
......@@ -759,3 +759,36 @@ def update_checksums_from(changed_paths, objects,
# Recompute hashes in memory from rootdir to root
return recompute_sha1_in_memory(root, rootdir, objects)
def objects_per_type(filter_type, objects_per_path):
"""Given an object dictionary returned by
`swh.model.git.walk_and_compute_sha1_from_directory_2`, yields
corresponding element type's hashes
Args:
filter_type: one of GitType enum
objects_per_path:
Yields:
Elements of type filter_type's hashes
"""
def __children_hash(objects, children):
for p in children:
c = objects.get(p, None)
if c:
h = c.get('checksums', None)
if h:
yield h
for path, obj in objects_per_path.items():
o = obj['checksums']
if o['type'] == filter_type:
if 'children' in obj: # for trees
if obj['children']:
o['children'] = __children_hash(objects_per_path,
obj['children'])
else:
o['children'] = []
yield o
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment