swh.vault.cookers.git_bare module

This cooker creates tarballs containing a bare .git directory, that can be unpacked and cloned like any git repository.

It works in three steps:

  1. Write objects one by one in .git/objects/

  2. Calls git repack to pack all these objects into git packfiles.

  3. Creates a tarball of the resulting repository

It keeps a set of all written (or about-to-be-written) object hashes in memory to avoid downloading and writing the same objects twice.

class swh.vault.cookers.git_bare.RootObjectType(value)[source]

Bases: enum.Enum

An enumeration.

DIRECTORY = 'directory'
REVISION = 'revision'
SNAPSHOT = 'snapshot'
swh.vault.cookers.git_bare.assert_never(value: NoReturn, msg) NoReturn[source]

mypy makes sure this function is never called, through exhaustive checking of value in the parent function.

See https://mypy.readthedocs.io/en/latest/literal_types.html#exhaustive-checks for details.

class swh.vault.cookers.git_bare.GitBareCooker(*args, **kwargs)[source]

Bases: swh.vault.cookers.base.BaseVaultCooker

Initialize the cooker.

The type of the object represented by the id depends on the concrete class. Very likely, each type of bundle will have its own cooker class.

Parameters
  • swhid – id of the object to be cooked into a bundle.

  • backend – the vault backend (swh.vault.backend.VaultBackend).

BUNDLE_TYPE: ClassVar[str] = 'git_bare'
SUPPORTED_OBJECT_TYPES: ClassVar[Set[ObjectType]] = {<ObjectType.DIRECTORY: 'dir'>, <ObjectType.REVISION: 'rev'>, <ObjectType.SNAPSHOT: 'snp'>}
use_fsck = True
obj_type: swh.vault.cookers.git_bare.RootObjectType
check_exists() bool[source]

Checks that the requested object exists and can be cooked.

Override this in the cooker implementation.

prepare_bundle()[source]

Implementation of the cooker. Yields chunks of the bundle bytes.

Override this with the cooker implementation.

init_git() None[source]
create_object_dirs() None[source]
repack() None[source]
git_fsck() None[source]
write_refs(snapshot=None)[source]
write_archive()[source]
object_exists(obj_id: bytes) bool[source]
write_object(obj_id: bytes, obj: bytes) bool[source]

Writes a git object on disk.

Returns whether it was already written.

push_subgraph(obj_type: swh.vault.cookers.git_bare.RootObjectType, obj_id) None[source]
load_objects() None[source]
push_revision_subgraph(obj_id: bytes) None[source]

Fetches a revision and all its children, and writes them to disk

push_snapshot_subgraph(obj_id: bytes) None[source]

Fetches a snapshot and all its children, and writes them to disk

load_revisions(obj_ids: List[bytes]) None[source]

Given a list of revision ids, loads these revisions and their directories; but not their parent revisions.

write_revision_node(revision: Dict[str, Any]) bool[source]

Writes a revision object to disk

load_releases(obj_ids: List[bytes]) List[swh.model.model.Release][source]

Loads release objects, and returns them.

push_releases_subgraphs(obj_ids: List[bytes]) None[source]

Given a list of release ids, loads these releases and adds their target to the list of objects to visit

write_release_node(release: Dict[str, Any]) bool[source]

Writes a release object to disk

load_directories(obj_ids: List[bytes]) None[source]
load_directory(obj_id: bytes) None[source]
load_contents(obj_ids: List[bytes]) None[source]
write_content(obj_id: bytes, content: bytes) None[source]