diff --git a/requirements-swh.txt b/requirements-swh.txt --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -1,3 +1,3 @@ swh.core[db,http] >= 0.0.60 swh.model >= 0.0.60 -swh.storage >= 0.0.177 +swh.storage >= 0.0.178 diff --git a/swh/journal/replay.py b/swh/journal/replay.py --- a/swh/journal/replay.py +++ b/swh/journal/replay.py @@ -26,7 +26,7 @@ from swh.model.hashutil import hash_to_hex from swh.model.model import ( - BaseContent, BaseModel, Content, Directory, Origin, Revision, + BaseContent, BaseModel, Content, Directory, Origin, OriginVisit, Revision, SHA1_SIZE, SkippedContent, Snapshot, Release ) from swh.objstorage.objstorage import ( @@ -205,8 +205,9 @@ return good_revisions -def _fix_origin_visits(visits: List[Dict]) -> List[Dict]: - """Adapt origin visits into a list of current storage compatible dicts. +def _fix_origin_visits(visits: List[Dict]) -> List[OriginVisit]: + """Adapt origin visits into a list of current storage compatible + OriginVisits. `visit['origin']` is a dict instead of an URL: @@ -214,14 +215,14 @@ >>> pprint(_fix_origin_visits([{ ... 'origin': {'url': 'http://foo'}, ... 'type': 'git', - ... }])) + ... }]).to_dict()) [{'metadata': None, 'origin': 'http://foo', 'type': 'git'}] `visit['type']` is missing , but `origin['visit']['type']` exists: >>> pprint(_fix_origin_visits([ ... {'origin': {'type': 'hg', 'url': 'http://foo'} - ... }])) + ... }]).to_dict()) [{'metadata': None, 'origin': 'http://foo', 'type': 'hg'}] """ @@ -242,7 +243,7 @@ visit['origin'] = visit['origin']['url'] if 'metadata' not in visit: visit['metadata'] = None - good_visits.append(visit) + good_visits.append(OriginVisit.from_dict(visit)) return good_visits @@ -309,9 +310,7 @@ ) elif object_type == 'origin_visit': visits = _fix_origin_visits(objects) - storage.origin_add(Origin(url=v['origin']) for v in visits) - # FIXME: Should be List[OriginVisit], working on fixing - # swh.storage.origin_visit_upsert (D2813) + storage.origin_add(Origin(url=v.origin) for v in visits) storage.origin_visit_upsert(visits) elif object_type in ('directory', 'release', 'snapshot', 'origin'): method = getattr(storage, object_type + '_add')