Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F11023662
D6073.id21987.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1005 B
Subscribers
None
D6073.id21987.diff
View Options
diff --git a/swh/graph/swhid.py b/swh/graph/swhid.py
--- a/swh/graph/swhid.py
+++ b/swh/graph/swhid.py
@@ -13,6 +13,7 @@
import struct
from typing import BinaryIO, Iterator, Tuple
+from swh.model.hashutil import hash_to_hex
from swh.model.identifiers import ExtendedObjectType, ExtendedSWHID
SWHID_BIN_FMT = "BB20s" # 2 unsigned chars + 20 bytes
@@ -86,10 +87,14 @@
"""
(version, type, bin_digest) = struct.unpack(SWHID_BIN_FMT, bytes)
- swhid = ExtendedSWHID(
- object_type=SwhidType(type).to_extended_object_type(), object_id=bin_digest
- )
- return str(swhid)
+
+ # The following is equivalent to:
+ # return str(ExtendedSWHID(
+ # object_type=SwhidType(type).to_extended_object_type(), object_id=bin_digest
+ # )
+ # but more efficient, because ExtendedSWHID.__init__ is extremely slow.
+ object_type = ExtendedObjectType[SwhidType(type).name.upper()]
+ return f"swh:1:{object_type.value}:{hash_to_hex(bin_digest)}"
class _OnDiskMap:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Sep 17, 4:55 PM (21 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3220160
Attached To
D6073: bytes_to_str: Format strings directly, instead of constructing ExtendedSWHID
Event Timeline
Log In to Comment