Changeset View
Changeset View
Standalone View
Standalone View
swh/dataset/graph.py
- This file was added.
# Copyright (C) 2019 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from swh.model.identifiers import origin_identifier | |||||
from swh.model.hashutil import hash_to_hex | |||||
ardumont: hashutil before identifiers | |||||
def process_messages(messages, output): | |||||
ardumontUnsubmitted Not Done Inline Actionsdocstrings? ardumont: docstrings? | |||||
def write(src, dst): | |||||
if src is None or dst is None: | |||||
return | |||||
print(hash_to_hex(src), hash_to_hex(dst), file=output) | |||||
for visit in messages.get('origin_visit', []): | |||||
write(origin_identifier({'url': visit['origin']}), visit['snapshot']) | |||||
for snapshot in messages.get('snapshot', []): | |||||
for branch in snapshot['branches'].values(): | |||||
while branch['target_type'] == 'alias': | |||||
branch = snapshot['branches'][branch['target']] | |||||
write(snapshot['id'], branch['target']) | |||||
for release in messages.get('release', []): | |||||
write(release['id'], release['target']) | |||||
for revision in messages.get('revision', []): | |||||
for parent in revision['parents']: | |||||
write(revision['id'], parent) | |||||
for directory in messages.get('directory', []): | |||||
for entry in directory['entries']: | |||||
write(directory['id'], entry['target']) |
hashutil before identifiers