Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123906
D6280.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D6280.diff
View Options
diff --git a/swh/loader/git/converters.py b/swh/loader/git/converters.py
--- a/swh/loader/git/converters.py
+++ b/swh/loader/git/converters.py
@@ -5,7 +5,9 @@
"""Convert dulwich objects to dictionaries suitable for swh.storage"""
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, cast
+
+from dulwich.objects import Blob, Commit, ShaFile, Tag, Tree
from swh.model.hashutil import DEFAULT_ALGORITHMS, MultiHash, hash_to_bytes
from swh.model.model import (
@@ -27,10 +29,11 @@
HASH_ALGORITHMS = DEFAULT_ALGORITHMS - {"sha1_git"}
-def dulwich_blob_to_content_id(blob) -> Dict[str, Any]:
+def dulwich_blob_to_content_id(obj: ShaFile) -> Dict[str, Any]:
"""Convert a dulwich blob to a Software Heritage content id"""
- if blob.type_name != b"blob":
+ if obj.type_name != b"blob":
raise ValueError("Argument is not a blob.")
+ blob = cast(Blob, obj)
size = blob.raw_length()
data = blob.as_raw_string()
@@ -40,12 +43,14 @@
return hashes
-def dulwich_blob_to_content(blob, max_content_size=None) -> BaseContent:
+def dulwich_blob_to_content(obj: ShaFile, max_content_size=None) -> BaseContent:
"""Convert a dulwich blob to a Software Heritage content
"""
- if blob.type_name != b"blob":
+ if obj.type_name != b"blob":
raise ValueError("Argument is not a blob.")
+ blob = cast(Blob, obj)
+
hashes = dulwich_blob_to_content_id(blob)
if max_content_size is not None and hashes["length"] >= max_content_size:
return SkippedContent(status="absent", reason="Content too large", **hashes,)
@@ -53,10 +58,11 @@
return Content(data=blob.as_raw_string(), status="visible", **hashes,)
-def dulwich_tree_to_directory(tree, log=None) -> Directory:
+def dulwich_tree_to_directory(obj: ShaFile, log=None) -> Directory:
"""Format a tree as a directory"""
- if tree.type_name != b"tree":
+ if obj.type_name != b"tree":
raise ValueError("Argument is not a tree.")
+ tree = cast(Tree, obj)
entries = []
@@ -98,9 +104,10 @@
)
-def dulwich_commit_to_revision(commit, log=None) -> Revision:
- if commit.type_name != b"commit":
+def dulwich_commit_to_revision(obj: ShaFile, log=None) -> Revision:
+ if obj.type_name != b"commit":
raise ValueError("Argument is not a commit.")
+ commit = cast(Commit, obj)
extra_headers = []
if commit.encoding is not None:
@@ -153,9 +160,10 @@
}
-def dulwich_tag_to_release(tag, log=None) -> Release:
- if tag.type_name != b"tag":
+def dulwich_tag_to_release(obj: ShaFile, log=None) -> Release:
+ if obj.type_name != b"tag":
raise ValueError("Argument is not a tag.")
+ tag = cast(Tag, obj)
target_type, target = tag.object
if tag.tagger:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Dec 20 2024, 6:00 AM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3226260
Attached To
D6280: converters: Add typing
Event Timeline
Log In to Comment