Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/revision_gitfast.py
Show All 12 Lines | from fastimport.commands import ( | ||||
CommitCommand, | CommitCommand, | ||||
FileDeleteCommand, | FileDeleteCommand, | ||||
FileModifyCommand, | FileModifyCommand, | ||||
ResetCommand, | ResetCommand, | ||||
) | ) | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.from_disk import DentryPerms, mode_to_perms | from swh.model.from_disk import DentryPerms, mode_to_perms | ||||
from swh.model.identifiers import ObjectType | |||||
from swh.model.toposort import toposort | from swh.model.toposort import toposort | ||||
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.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" | BUNDLE_TYPE = "gitfast" | ||||
SUPPORTED_OBJECT_TYPES = {ObjectType.REVISION} | |||||
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(revision_log(self.storage, 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() | ||||
Show All 14 Lines | def fastexport(self): | ||||
last_progress_report = None | last_progress_report = None | ||||
for i, rev in enumerate(self.log, 1): | for i, rev in enumerate(self.log, 1): | ||||
# Update progress if needed | # Update progress if needed | ||||
ct = time.time() | ct = time.time() | ||||
if last_progress_report is None or last_progress_report + 2 <= ct: | if last_progress_report is None or last_progress_report + 2 <= ct: | ||||
last_progress_report = ct | last_progress_report = ct | ||||
pg = "Computing revision {}/{}".format(i, len(self.log)) | pg = "Computing revision {}/{}".format(i, len(self.log)) | ||||
self.backend.set_progress(self.bundle_type, self.obj_id, pg) | self.backend.set_progress(self.BUNDLE_TYPE, self.swhid, pg) | ||||
# Compute the current commit | # Compute the current commit | ||||
self._compute_commit_command(rev) | self._compute_commit_command(rev) | ||||
def mark(self, obj_id): | def mark(self, obj_id): | ||||
"""Get the mark ID as bytes of a git object. | """Get the mark ID as bytes of a git object. | ||||
If the object has not yet been marked, assign a new ID and add it to | If the object has not yet been marked, assign a new ID and add it to | ||||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |