Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/loader.py
Show First 20 Lines • Show All 464 Lines • ▼ Show 20 Lines | def get_revisions(self) -> Iterable[Revision]: | ||||
self.num_revisions += 1 | self.num_revisions += 1 | ||||
date_dict = identifiers.normalize_timestamp(int(commit["time"].timestamp())) | date_dict = identifiers.normalize_timestamp(int(commit["time"].timestamp())) | ||||
author_dict = converters.parse_author(commit["user"]) | author_dict = converters.parse_author(commit["user"]) | ||||
if commit["manifest"] == Bundle20Reader.NAUGHT_NODE: | if commit["manifest"] == Bundle20Reader.NAUGHT_NODE: | ||||
directory_id = SimpleTree().hash_changed() | directory_id = SimpleTree().hash_changed() | ||||
else: | else: | ||||
directory_id = self.mnode_to_tree_id[commit["manifest"]] | directory_id = self.mnode_to_tree_id[commit["manifest"]] | ||||
extra_meta = [] | extra_headers = [ | ||||
( | |||||
b"time_offset_seconds", | |||||
str(commit["time_offset_seconds"]).encode("utf-8"), | |||||
) | |||||
] | |||||
extra = commit.get("extra") | extra = commit.get("extra") | ||||
if extra: | if extra: | ||||
for e in extra.split(b"\x00"): | for e in extra.split(b"\x00"): | ||||
k, v = e.split(b":", 1) | k, v = e.split(b":", 1) | ||||
k = k.decode("utf-8") | |||||
# transplant_source stores binary reference to a changeset | # transplant_source stores binary reference to a changeset | ||||
# prefer to dump hexadecimal one in the revision metadata | # prefer to dump hexadecimal one in the revision metadata | ||||
if k == "transplant_source": | if k == b"transplant_source": | ||||
v = hash_to_bytehex(v) | v = hash_to_bytehex(v) | ||||
extra_meta.append([k, v]) | extra_headers.append((k, v)) | ||||
parents = [] | parents = [] | ||||
p1 = self.node_2_rev.get(header["p1"]) | p1 = self.node_2_rev.get(header["p1"]) | ||||
p2 = self.node_2_rev.get(header["p2"]) | p2 = self.node_2_rev.get(header["p2"]) | ||||
if p1: | if p1: | ||||
parents.append(p1) | parents.append(p1) | ||||
if p2: | if p2: | ||||
parents.append(p2) | parents.append(p2) | ||||
revision = Revision( | revision = Revision( | ||||
author=Person.from_dict(author_dict), | author=Person.from_dict(author_dict), | ||||
date=TimestampWithTimezone.from_dict(date_dict), | date=TimestampWithTimezone.from_dict(date_dict), | ||||
committer=Person.from_dict(author_dict), | committer=Person.from_dict(author_dict), | ||||
committer_date=TimestampWithTimezone.from_dict(date_dict), | committer_date=TimestampWithTimezone.from_dict(date_dict), | ||||
type=RevisionType.MERCURIAL, | type=RevisionType.MERCURIAL, | ||||
directory=directory_id, | directory=directory_id, | ||||
message=commit["message"], | message=commit["message"], | ||||
metadata={ | metadata={"node": hash_to_hex(header["node"]),}, | ||||
"node": hash_to_hex(header["node"]), | extra_headers=tuple(extra_headers), | ||||
"extra_headers": [ | |||||
[ | |||||
"time_offset_seconds", | |||||
str(commit["time_offset_seconds"]).encode("utf-8"), | |||||
], | |||||
] | |||||
+ extra_meta, | |||||
}, | |||||
synthetic=False, | synthetic=False, | ||||
parents=tuple(parents), | parents=tuple(parents), | ||||
) | ) | ||||
self.node_2_rev[header["node"]] = revision.id | self.node_2_rev[header["node"]] = revision.id | ||||
revisions[revision.id] = revision | revisions[revision.id] = revision | ||||
# Converts heads to use swh ids | # Converts heads to use swh ids | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |