Changeset View
Changeset View
Standalone View
Standalone View
swh/model/identifiers.py
Show First 20 Lines • Show All 420 Lines • ▼ Show 20 Lines | def revision_identifier(revision): | ||||
The fields used for the revision identifier computation are: | The fields used for the revision identifier computation are: | ||||
- directory | - directory | ||||
- parents | - parents | ||||
- author | - author | ||||
- author_date | - author_date | ||||
- committer | - committer | ||||
- committer_date | - committer_date | ||||
- metadata -> extra_headers | - extra_headers or metadata -> extra_headers | ||||
- message | - message | ||||
A revision's identifier is the 'git'-checksum of a commit manifest | A revision's identifier is the 'git'-checksum of a commit manifest | ||||
constructed as follows (newlines are a single ASCII newline character):: | constructed as follows (newlines are a single ASCII newline character):: | ||||
tree <directory identifier> | tree <directory identifier> | ||||
[for each parent in parents] | [for each parent in parents] | ||||
parent <parent identifier> | parent <parent identifier> | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | components.extend( | ||||
format_author_line("author", revision["author"], revision["date"]), | format_author_line("author", revision["author"], revision["date"]), | ||||
format_author_line( | format_author_line( | ||||
"committer", revision["committer"], revision["committer_date"] | "committer", revision["committer"], revision["committer_date"] | ||||
), | ), | ||||
] | ] | ||||
) | ) | ||||
# Handle extra headers | # Handle extra headers | ||||
metadata = revision.get("metadata") | metadata = revision.get("metadata") or {} | ||||
if not metadata: | extra_headers = revision.get("extra_headers", ()) | ||||
metadata = {} | if not extra_headers and "extra_headers" in metadata: | ||||
extra_headers = metadata["extra_headers"] | |||||
for key, value in metadata.get("extra_headers", []): | |||||
# Integer values: decimal representation | |||||
if isinstance(value, int): | |||||
value = str(value).encode("utf-8") | |||||
# Unicode string values: utf-8 encoding | |||||
if isinstance(value, str): | |||||
value = value.encode("utf-8") | |||||
# encode the key to utf-8 | for key, value in extra_headers: | ||||
components.extend([key.encode("utf-8"), b" ", escape_newlines(value), b"\n"]) | components.extend([key, b" ", escape_newlines(value), b"\n"]) | ||||
if revision["message"] is not None: | if revision["message"] is not None: | ||||
components.extend([b"\n", revision["message"]]) | components.extend([b"\n", revision["message"]]) | ||||
commit_raw = b"".join(components) | commit_raw = b"".join(components) | ||||
return identifier_to_str(hash_git_data(commit_raw, "commit")) | return identifier_to_str(hash_git_data(commit_raw, "commit")) | ||||
▲ Show 20 Lines • Show All 358 Lines • Show Last 20 Lines |