Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/git_bare.py
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | def load_directory(self, obj_id: Sha1Git) -> None: | ||||
stack = entry_loaders[entry["type"]] | stack = entry_loaders[entry["type"]] | ||||
self._push(stack, [entry["target"]]) | self._push(stack, [entry["target"]]) | ||||
def load_contents(self, obj_ids: List[Sha1Git]) -> None: | def load_contents(self, obj_ids: List[Sha1Git]) -> None: | ||||
# TODO: add support of filtered objects, somehow? | # TODO: add support of filtered objects, somehow? | ||||
# It's tricky, because, by definition, we can't write a git object with | # It's tricky, because, by definition, we can't write a git object with | ||||
# the expected hash, so git-fsck *will* choke on it. | # the expected hash, so git-fsck *will* choke on it. | ||||
contents = self.storage.content_get(obj_ids, "sha1_git") | contents = self.storage.content_get(obj_ids, "sha1_git") | ||||
for (obj_id, content) in zip(obj_ids, contents): | |||||
assert obj_id == content.sha1_git # just to be sure | if self.objstorage is None: | ||||
content = self.storage.content_get_data(content.sha1) | for content in contents: | ||||
self.write_object( | data = self.storage.content_get_data(content.sha1) | ||||
obj_id, f"blob {len(content)}\0".encode("ascii") + content | self.write_content(content.sha1_git, data) | ||||
) | else: | ||||
content_data = self.objstorage.get_batch(c.sha1 for c in contents) | |||||
for (content, data) in zip(contents, content_data): | |||||
self.write_content(content.sha1_git, data) | |||||
def write_content(self, obj_id: Sha1Git, content: bytes) -> None: | |||||
self.write_object(obj_id, f"blob {len(content)}\0".encode("ascii") + content) |