swh.loader.git.utils module#

Utilities helper functions

swh.loader.git.utils.init_git_repo_from_archive(project_name, archive_path, root_temp_dir='/tmp')[source]#

Given a path to an archive containing a git repository.

Uncompress that archive to a temporary location and returns the path.

If any problem whatsoever is raised, clean up the temporary location.

Parameters:
  • project_name (str) – Project’s name

  • archive_path (str) – Full path to the archive

  • root_temp_dir (str) – Optional temporary directory mount point (default to /tmp)

Returns

A tuple: - temporary folder: containing the mounted repository - repo_path, path to the mounted repository inside the temporary folder

Raises

ValueError in case of failure to run the command to uncompress

swh.loader.git.utils.check_date_time(timestamp)[source]#

Check date time for overflow errors.

Parameters:

timestamp (timestamp) – Timestamp in seconds

Raises:

Any error raised by datetime fromtimestamp conversion error.

swh.loader.git.utils.ignore_branch_name(branch_name: bytes) bool[source]#

Should the git loader ignore the branch named branch_name?

swh.loader.git.utils.filter_refs(refs: Mapping[bytes, bytes | HexBytes]) Dict[bytes, HexBytes][source]#

Filter the refs dictionary using the policy set in ignore_branch_name

swh.loader.git.utils.warn_dangling_branches(branches: Dict[bytes, SnapshotBranch | None], dangling_branches: Dict[HexBytes, bytes], logger: Logger, origin_url: str) None[source]#
swh.loader.git.utils.raise_not_found_repository()[source]#

Catches all kinds of exceptions which translate to an inexistent repository and reraise as a NotFound exception. Any other exceptions are propagated to the caller.

Raises:
  • NotFound – instead of HTTPUnauthorized, NotGitRepository and any GitProtocol with specific error message relative to an inexistent repository.

  • * – Any other exceptions raised within the try block

class swh.loader.git.utils.PackWriter(pack_buffer: SpooledTemporaryFile, size_limit: int, origin_url: str, fetch_pack_logger: Logger)[source]#

Bases: object

Helper class to abort git loading if pack file currently downloaded has a size in bytes that exceeds a given threshold.

write(data: bytes)[source]#