Changeset View
Changeset View
Standalone View
Standalone View
swh/model/git_objects.py
Show All 33 Lines | |||||
from typing import Dict, Iterable, List, Optional, Tuple, Union, cast | from typing import Dict, Iterable, List, Optional, Tuple, Union, cast | ||||
import warnings | import warnings | ||||
from . import model | from . import model | ||||
from .collections import ImmutableDict | from .collections import ImmutableDict | ||||
from .hashutil import git_object_header, hash_to_bytehex | from .hashutil import git_object_header, hash_to_bytehex | ||||
def content_git_object(content: model.Content) -> bytes: | |||||
"""Formats a content as a git blob. | |||||
A content's identifier is the blob sha1 à la git of the tagged content. | |||||
""" | |||||
content = cast(model.Content, content) | |||||
if content.data is None: | |||||
raise model.MissingData("Content data is None, cannot format.") | |||||
return git_object_header("blob", len(content.data)) + content.data | |||||
def directory_entry_sort_key(entry: model.DirectoryEntry): | def directory_entry_sort_key(entry: model.DirectoryEntry): | ||||
"""The sorting key for tree entries""" | """The sorting key for tree entries""" | ||||
if isinstance(entry, dict): | if isinstance(entry, dict): | ||||
# For backward compatibility | # For backward compatibility | ||||
entry = model.DirectoryEntry.from_dict(entry) | entry = model.DirectoryEntry.from_dict(entry) | ||||
if entry.type == "dir": | if entry.type == "dir": | ||||
return entry.name + b"/" | return entry.name + b"/" | ||||
else: | else: | ||||
▲ Show 20 Lines • Show All 589 Lines • Show Last 20 Lines |