Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/common.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 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 swh.model.hashutil import MultiHash | from typing import Optional | ||||||||||||
from swh.model.hashutil import MultiHash, hash_to_bytes | |||||||||||||
from swh.model.model import Revision | |||||||||||||
def origin_url_to_sha1(origin_url: str) -> bytes: | def origin_url_to_sha1(origin_url: str) -> bytes: | ||||||||||||
"""Convert an origin URL to a sha1. Encodes URL to utf-8.""" | """Convert an origin URL to a sha1. Encodes URL to utf-8.""" | ||||||||||||
return MultiHash.from_data(origin_url.encode("utf-8"), {"sha1"}).digest()["sha1"] | return MultiHash.from_data(origin_url.encode("utf-8"), {"sha1"}).digest()["sha1"] | ||||||||||||
def revision_to_vcsid(revision: Revision) -> Optional[bytes]: | |||||||||||||
zack: Naming nitpick, as we discussed (at least tentatively) in T2849, this is not going to be VCS… | |||||||||||||
vlorentzUnsubmitted Done Inline ActionsAlready bikeshedded (via Jitsi), and we agreed on using the name "vcsid" anyway. I would be fine with "extid", though. vlorentz: Already bikeshedded (via Jitsi), and we agreed on using the name "vcsid" anyway.
I would be… | |||||||||||||
"""Get the original VCS intrinsic identifier for the given revision""" | |||||||||||||
if revision.type.value == "git": | |||||||||||||
return revision.id | |||||||||||||
if revision.type.value == "hg": | |||||||||||||
Not Done Inline Actions
vlorentz: | |||||||||||||
Done Inline Actionsactually this function is not used any more, forgot to remove it... douardda: actually this function is not used any more, forgot to remove it... | |||||||||||||
node = None | |||||||||||||
if revision.extra_headers: | |||||||||||||
node = dict(revision.extra_headers).get(b"node") | |||||||||||||
if node is None and revision.metadata: | |||||||||||||
node = hash_to_bytes(revision.metadata.get("node")) | |||||||||||||
return node | |||||||||||||
# fall back | |||||||||||||
return None # or revision.id ? |
Naming nitpick, as we discussed (at least tentatively) in T2849, this is not going to be VCS-only, we might have external IDs also for stuff like tarballs and other archives.
So, should we call these things "external IDs", rather than "VCS IDs"?
And, if so, rename revision_to_vcsid to revision_to_extid.
Or something.