Page MenuHomeSoftware Heritage

D6073.id21987.diff
No OneTemporary

D6073.id21987.diff

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

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

Event Timeline