Changeset View
Changeset View
Standalone View
Standalone View
swh/model/from_disk.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2018 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 | ||||
import enum | import enum | ||||
import os | import os | ||||
import stat | import stat | ||||
from typing import List | |||||
from .hashutil import MultiHash, HASH_BLOCK_SIZE | from .hashutil import MultiHash, HASH_BLOCK_SIZE | ||||
from .merkle import MerkleLeaf, MerkleNode | from .merkle import MerkleLeaf, MerkleNode | ||||
from .identifiers import ( | from .identifiers import ( | ||||
directory_identifier, | directory_identifier, | ||||
identifier_to_bytes as id_to_bytes, | identifier_to_bytes as id_to_bytes, | ||||
identifier_to_str as id_to_str, | identifier_to_str as id_to_str, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
class Content(MerkleLeaf): | class Content(MerkleLeaf): | ||||
"""Representation of a Software Heritage content as a node in a Merkle tree. | """Representation of a Software Heritage content as a node in a Merkle tree. | ||||
The current Merkle hash for the Content nodes is the `sha1_git`, which | The current Merkle hash for the Content nodes is the `sha1_git`, which | ||||
makes it consistent with what :class:`Directory` uses for its own hash | makes it consistent with what :class:`Directory` uses for its own hash | ||||
computation. | computation. | ||||
""" | """ | ||||
__slots__ = [] | __slots__ = [] # type: List[str] | ||||
type = 'content' | type = 'content' | ||||
@classmethod | @classmethod | ||||
def from_bytes(cls, *, mode, data): | def from_bytes(cls, *, mode, data): | ||||
"""Convert data (raw :class:`bytes`) to a Software Heritage content entry | """Convert data (raw :class:`bytes`) to a Software Heritage content entry | ||||
Args: | Args: | ||||
mode (int): a file mode (passed to :func:`mode_to_perms`) | mode (int): a file mode (passed to :func:`mode_to_perms`) | ||||
▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines |