Changeset View
Changeset View
Standalone View
Standalone View
swh/model/git_objects.py
Show First 20 Lines • Show All 625 Lines • ▼ Show 20 Lines | def extid_git_object(extid: model.ExtID) -> bytes: | ||||||||||||
An ExtID identifier is a salted sha1 (using the git hashing algorithm with | An ExtID identifier is a salted sha1 (using the git hashing algorithm with | ||||||||||||
the ``extid`` object type) of a manifest following the format: | the ``extid`` object type) of a manifest following the format: | ||||||||||||
``` | ``` | ||||||||||||
extid_type $StrWithoutSpaces | extid_type $StrWithoutSpaces | ||||||||||||
[extid_version $Str] | [extid_version $Str] | ||||||||||||
extid $Bytes | extid $Bytes | ||||||||||||
target $CoreSwhid | target $CoreSwhid | ||||||||||||
[payload_type $StrWithoutSpaces] | |||||||||||||
[payload $ContentIdentifier] | |||||||||||||
``` | ``` | ||||||||||||
$StrWithoutSpaces is an ASCII string, and may not contain spaces. | $StrWithoutSpaces is an ASCII string, and may not contain spaces. | ||||||||||||
Newlines in $Bytes are escaped as with other git fields, ie. by adding a | Newlines in $Bytes are escaped as with other git fields, ie. by adding a | ||||||||||||
space after them. | space after them. | ||||||||||||
The extid_version line is only generated if the version is non-zero. | The extid_version line is only generated if the version is non-zero. | ||||||||||||
The payload_type and payload lines are only generated if they are not | |||||||||||||
vlorentzUnsubmitted Not Done Inline Actions
vlorentz: | |||||||||||||
:const:`None`. $ContentIdentifier is the object ID of a content object. | |||||||||||||
""" | """ | ||||||||||||
headers = [ | headers = [ | ||||||||||||
(b"extid_type", extid.extid_type.encode("ascii")), | (b"extid_type", extid.extid_type.encode("ascii")), | ||||||||||||
] | ] | ||||||||||||
extid_version = extid.extid_version | extid_version = extid.extid_version | ||||||||||||
if extid_version != 0: | if extid_version != 0: | ||||||||||||
headers.append((b"extid_version", str(extid_version).encode("ascii"))) | headers.append((b"extid_version", str(extid_version).encode("ascii"))) | ||||||||||||
headers.extend( | headers.extend( | ||||||||||||
[ | [ | ||||||||||||
(b"extid", extid.extid), | (b"extid", extid.extid), | ||||||||||||
(b"target", str(extid.target).encode("ascii")), | (b"target", str(extid.target).encode("ascii")), | ||||||||||||
] | ] | ||||||||||||
) | ) | ||||||||||||
payload_type = extid.payload_type | |||||||||||||
if payload_type is not None: | |||||||||||||
Not Done Inline Actions
vlorentz: | |||||||||||||
headers.append((b"payload_type", payload_type.encode("ascii"))) | |||||||||||||
payload = extid.payload | |||||||||||||
if payload is not None: | |||||||||||||
headers.append((b"payload", payload)) | |||||||||||||
return format_git_object_from_headers("extid", headers) | return format_git_object_from_headers("extid", headers) |