Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/converters.py
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | def dulwich_blob_to_content(obj: ShaFile, max_content_size=None) -> BaseContent: | ||||
hashes = dulwich_blob_to_content_id(blob) | hashes = dulwich_blob_to_content_id(blob) | ||||
if max_content_size is not None and hashes["length"] >= max_content_size: | if max_content_size is not None and hashes["length"] >= max_content_size: | ||||
return SkippedContent(status="absent", reason="Content too large", **hashes,) | return SkippedContent(status="absent", reason="Content too large", **hashes,) | ||||
else: | else: | ||||
return Content(data=blob.as_raw_string(), status="visible", **hashes,) | return Content(data=blob.as_raw_string(), status="visible", **hashes,) | ||||
def dulwich_tree_to_directory(obj: ShaFile, log=None) -> Directory: | def dulwich_tree_to_directory(obj: ShaFile) -> Directory: | ||||
"""Format a tree as a directory""" | """Format a tree as a directory""" | ||||
if obj.type_name != b"tree": | if obj.type_name != b"tree": | ||||
raise ValueError("Argument is not a tree.") | raise ValueError("Argument is not a tree.") | ||||
tree = cast(Tree, obj) | tree = cast(Tree, obj) | ||||
entries = [] | entries = [] | ||||
entry_mode_map = { | entry_mode_map = { | ||||
Show All 31 Lines | ) -> TimestampWithTimezone: | ||||
Software Heritage""" | Software Heritage""" | ||||
return TimestampWithTimezone( | return TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=int(timestamp), microseconds=0,), | timestamp=Timestamp(seconds=int(timestamp), microseconds=0,), | ||||
offset=timezone // 60, | offset=timezone // 60, | ||||
negative_utc=timezone_neg_utc if timezone == 0 else False, | negative_utc=timezone_neg_utc if timezone == 0 else False, | ||||
) | ) | ||||
def dulwich_commit_to_revision(obj: ShaFile, log=None) -> Revision: | def dulwich_commit_to_revision(obj: ShaFile) -> Revision: | ||||
if obj.type_name != b"commit": | if obj.type_name != b"commit": | ||||
raise ValueError("Argument is not a commit.") | raise ValueError("Argument is not a commit.") | ||||
commit = cast(Commit, obj) | commit = cast(Commit, obj) | ||||
extra_headers = [] | extra_headers = [] | ||||
if commit.encoding is not None: | if commit.encoding is not None: | ||||
extra_headers.append((b"encoding", commit.encoding)) | extra_headers.append((b"encoding", commit.encoding)) | ||||
if commit.mergetag: | if commit.mergetag: | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
DULWICH_OBJECT_TYPES = { | DULWICH_OBJECT_TYPES = { | ||||
b"blob": ObjectType.CONTENT, | b"blob": ObjectType.CONTENT, | ||||
b"tree": ObjectType.DIRECTORY, | b"tree": ObjectType.DIRECTORY, | ||||
b"commit": ObjectType.REVISION, | b"commit": ObjectType.REVISION, | ||||
b"tag": ObjectType.RELEASE, | b"tag": ObjectType.RELEASE, | ||||
} | } | ||||
def dulwich_tag_to_release(obj: ShaFile, log=None) -> Release: | def dulwich_tag_to_release(obj: ShaFile) -> Release: | ||||
if obj.type_name != b"tag": | if obj.type_name != b"tag": | ||||
raise ValueError("Argument is not a tag.") | raise ValueError("Argument is not a tag.") | ||||
tag = cast(Tag, obj) | tag = cast(Tag, obj) | ||||
target_type, target = tag.object | target_type, target = tag.object | ||||
if tag.tagger: | if tag.tagger: | ||||
author: Optional[Person] = parse_author(tag.tagger) | author: Optional[Person] = parse_author(tag.tagger) | ||||
if not tag.tag_time: | if not tag.tag_time: | ||||
Show All 25 Lines |