Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/revision_gitfast.py
# Copyright (C) 2017 The Software Heritage developers | # Copyright (C) 2017-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import functools | import functools | ||||
import os | import os | ||||
import time | import time | ||||
import zlib | import zlib | ||||
from fastimport.commands import (CommitCommand, ResetCommand, BlobCommand, | from fastimport.commands import (CommitCommand, ResetCommand, BlobCommand, | ||||
FileDeleteCommand, FileModifyCommand) | FileDeleteCommand, FileModifyCommand) | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.toposort import toposort | from swh.model.toposort import toposort | ||||
from swh.model.from_disk import mode_to_perms | from swh.model.from_disk import mode_to_perms | ||||
from swh.vault.cookers.base import BaseVaultCooker | from swh.vault.cookers.base import BaseVaultCooker | ||||
from swh.vault.cookers.utils import revision_log | |||||
from swh.vault.to_disk import get_filtered_files_content | from swh.vault.to_disk import get_filtered_files_content | ||||
class RevisionGitfastCooker(BaseVaultCooker): | class RevisionGitfastCooker(BaseVaultCooker): | ||||
"""Cooker to create a git fast-import bundle """ | """Cooker to create a git fast-import bundle """ | ||||
CACHE_TYPE_KEY = 'revision_gitfast' | CACHE_TYPE_KEY = 'revision_gitfast' | ||||
def check_exists(self): | def check_exists(self): | ||||
return not list(self.storage.revision_missing([self.obj_id])) | return not list(self.storage.revision_missing([self.obj_id])) | ||||
def prepare_bundle(self): | def prepare_bundle(self): | ||||
self.log = list(toposort(self.storage.revision_log([self.obj_id]))) | self.log = list(toposort(revision_log(self.storage, self.obj_id))) | ||||
self.gzobj = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS | 16) | self.gzobj = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS | 16) | ||||
self.fastexport() | self.fastexport() | ||||
self.write(self.gzobj.flush()) | self.write(self.gzobj.flush()) | ||||
def write_cmd(self, cmd): | def write_cmd(self, cmd): | ||||
chunk = bytes(cmd) + b'\n' | chunk = bytes(cmd) + b'\n' | ||||
super().write(self.gzobj.compress(chunk)) | super().write(self.gzobj.compress(chunk)) | ||||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |