Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/converters.py
# Copyright (C) 2015-2017 The Software Heritage developers | # Copyright (C) 2015-2019 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 | ||||
"""Convert dulwich objects to dictionaries suitable for swh.storage""" | """Convert dulwich objects to dictionaries suitable for swh.storage""" | ||||
from swh.model import identifiers | from swh.model import identifiers | ||||
from swh.model.hashutil import ( | from swh.model.hashutil import ( | ||||
DEFAULT_ALGORITHMS, hash_to_hex, hash_to_bytes, MultiHash | DEFAULT_ALGORITHMS, hash_to_hex, hash_to_bytes, MultiHash | ||||
) | ) | ||||
HASH_ALGORITHMS = DEFAULT_ALGORITHMS - {'sha1_git'} | HASH_ALGORITHMS = DEFAULT_ALGORITHMS - {'sha1_git'} | ||||
def origin_url_to_origin(origin_url): | def origin_url_to_origin(origin_url): | ||||
"""Format a pygit2.Repository as an origin suitable for swh.storage""" | """Format a pygit2.Repository as an origin suitable for swh.storage""" | ||||
return { | return { | ||||
'type': 'git', | |||||
'url': origin_url, | 'url': origin_url, | ||||
} | } | ||||
def dulwich_blob_to_content_id(blob): | def dulwich_blob_to_content_id(blob): | ||||
"""Convert a dulwich blob to a Software Heritage content id""" | """Convert a dulwich blob to a Software Heritage content id""" | ||||
if blob.type_name != b'blob': | if blob.type_name != b'blob': | ||||
return | return | ||||
▲ Show 20 Lines • Show All 210 Lines • Show Last 20 Lines |