Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/revision_gitfast.py
# Copyright (C) 2017 The Software Heritage developers | # Copyright (C) 2017 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.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.to_disk import get_filtered_file_content | from swh.vault.to_disk import get_filtered_file_content | ||||
class RevisionGitfastCooker(BaseVaultCooker): | class RevisionGitfastCooker(BaseVaultCooker): | ||||
"""Cooker to create a git fast-import bundle """ | """Cooker to create a git fast-import bundle """ | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | def _compute_file_commands(self, rev, parent=None): | ||||
or f['perms'] != prev_dir[fname]['perms'])): | or f['perms'] != prev_dir[fname]['perms'])): | ||||
# Issue a blob command for the new blobs if needed. | # Issue a blob command for the new blobs if needed. | ||||
self._compute_blob_command_content(f) | self._compute_blob_command_content(f) | ||||
yield FileModifyCommand( | yield FileModifyCommand( | ||||
path=os.path.join(root, fname), | path=os.path.join(root, fname), | ||||
mode=mode_to_perms(f['perms']).value, | mode=mode_to_perms(f['perms']).value, | ||||
dataref=(b':' + self.mark(f['sha1'])), | dataref=(b':' + self.mark(f['sha1'])), | ||||
data=None) | data=None) | ||||
# A revision is added or modified if it was not in the tree or | |||||
# if its target changed | |||||
elif (f['type'] == 'rev' | |||||
and (fname not in prev_dir | |||||
or f['target'] != prev_dir[fname]['target'])): | |||||
yield FileModifyCommand( | |||||
path=os.path.join(root, fname), | |||||
mode=0o160000, | |||||
dataref=hashutil.hash_to_hex(f['target']).encode(), | |||||
data=None) | |||||
# A directory is added or modified if it was not in the tree or | # A directory is added or modified if it was not in the tree or | ||||
# if its target changed. | # if its target changed. | ||||
elif f['type'] == 'dir': | elif f['type'] == 'dir': | ||||
f_prev_target = None | f_prev_target = None | ||||
if fname in prev_dir and prev_dir[fname]['type'] == 'dir': | if fname in prev_dir and prev_dir[fname]['type'] == 'dir': | ||||
f_prev_target = prev_dir[fname]['target'] | f_prev_target = prev_dir[fname]['target'] | ||||
if f_prev_target is None or f['target'] != f_prev_target: | if f_prev_target is None or f['target'] != f_prev_target: | ||||
stack.append((os.path.join(root, fname), | stack.append((os.path.join(root, fname), | ||||
f['target'], f_prev_target)) | f['target'], f_prev_target)) |