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 collections | import collections | ||||
import fastimport.commands | import fastimport.commands | ||||
import functools | import functools | ||||
import os | import os | ||||
import time | import time | ||||
import zlib | import zlib | ||||
from .base import BaseVaultCooker, get_filtered_file_content | from .base import BaseVaultCooker, get_filtered_file_content | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.from_disk import mode_to_perms | |||||
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): | ||||
if list(self.storage.revision_missing([self.obj_id])): | if list(self.storage.revision_missing([self.obj_id])): | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | def _compute_file_commands(self, rev, parent=None): | ||||
if (f['type'] == 'file' | if (f['type'] == 'file' | ||||
and (fname not in prev_dir | and (fname not in prev_dir | ||||
or f['sha1'] != prev_dir[fname]['sha1'] | or f['sha1'] != prev_dir[fname]['sha1'] | ||||
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. | ||||
yield from self._compute_blob_command_content(f) | yield from self._compute_blob_command_content(f) | ||||
commands.append(fastimport.commands.FileModifyCommand( | commands.append(fastimport.commands.FileModifyCommand( | ||||
path=os.path.join(root, fname), | path=os.path.join(root, fname), | ||||
mode=f['perms'], | mode=mode_to_perms(f['perms']).value, | ||||
dataref=(b':' + self.mark(f['sha1'])), | dataref=(b':' + self.mark(f['sha1'])), | ||||
data=None, | 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)) | ||||
return commands | return commands |