Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/model.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from __future__ import annotations | from __future__ import annotations | ||||
from datetime import datetime | from datetime import datetime | ||||
from typing import Iterable, Iterator, List, Optional | from typing import Iterable, Iterator, List, Optional | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.model import Origin, Sha1Git | ||||
from swh.model.identifiers import origin_identifier | |||||
from swh.model.model import Sha1Git | |||||
from .archive import ArchiveInterface | from .archive import ArchiveInterface | ||||
class OriginEntry: | class OriginEntry: | ||||
def __init__(self, url: str, snapshot: Sha1Git) -> None: | def __init__(self, url: str, snapshot: Sha1Git) -> None: | ||||
self.url = url | self.url = url | ||||
self.id: Sha1Git = hash_to_bytes(origin_identifier({"url": self.url})) | self.id = Origin(url=self.url).id | ||||
self.snapshot = snapshot | self.snapshot = snapshot | ||||
self._revisions: Optional[List[RevisionEntry]] = None | self._revisions: Optional[List[RevisionEntry]] = None | ||||
def retrieve_revisions(self, archive: ArchiveInterface) -> None: | def retrieve_revisions(self, archive: ArchiveInterface) -> None: | ||||
if self._revisions is None: | if self._revisions is None: | ||||
self._revisions = [ | self._revisions = [ | ||||
RevisionEntry(rev) for rev in archive.snapshot_get_heads(self.snapshot) | RevisionEntry(rev) for rev in archive.snapshot_get_heads(self.snapshot) | ||||
] | ] | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |