Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/utils.py
# Copyright (C) 2017 The Software Heritage developers | # Copyright (C) 2017-2020 The Software Heritage developers | ||||
ardumont: I am "the pre-commit hook" for copyright headers (I missed those yesterday... ;)
Can you please… | |||||
Not Done Inline ActionsI got retired... maybe? \m/ D3191 ardumont: I got retired... maybe? \m/ D3191 | |||||
# 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 | ||||
"""Utilities helper functions""" | """Utilities helper functions""" | ||||
import datetime | import datetime | ||||
import logging | |||||
import os | import os | ||||
import shutil | import shutil | ||||
import tempfile | import tempfile | ||||
from typing import Dict, Optional | |||||
from swh.core import tarball | from swh.core import tarball | ||||
from swh.model.model import SnapshotBranch | |||||
def init_git_repo_from_archive(project_name, archive_path, root_temp_dir="/tmp"): | def init_git_repo_from_archive(project_name, archive_path, root_temp_dir="/tmp"): | ||||
"""Given a path to an archive containing a git repository. | """Given a path to an archive containing a git repository. | ||||
Uncompress that archive to a temporary location and returns the path. | Uncompress that archive to a temporary location and returns the path. | ||||
If any problem whatsoever is raised, clean up the temporary location. | If any problem whatsoever is raised, clean up the temporary location. | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | def check_date_time(timestamp): | ||||
Raise: | Raise: | ||||
Any error raised by datetime fromtimestamp conversion error. | Any error raised by datetime fromtimestamp conversion error. | ||||
""" | """ | ||||
if not timestamp: | if not timestamp: | ||||
return None | return None | ||||
datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc) | datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc) | ||||
def warn_dangling_branches( | |||||
branches: Dict[bytes, Optional[SnapshotBranch]], | |||||
dangling_branches: Dict[bytes, bytes], | |||||
logger: logging.Logger, | |||||
origin_url: str, | |||||
) -> None: | |||||
dangling_branches = { | |||||
target: ref for target, ref in dangling_branches.items() if not branches[target] | |||||
} | |||||
if dangling_branches: | |||||
descr = [f"{ref!r}->{target!r}" for target, ref in dangling_branches.items()] | |||||
logger.warning( | |||||
"Dangling symbolic references: %s", | |||||
", ".join(descr), | |||||
extra={ | |||||
"swh_type": "swh_loader_git_dangling_symrefs", | |||||
"swh_refs": descr, | |||||
"origin_url": origin_url, | |||||
}, | |||||
) |
I am "the pre-commit hook" for copyright headers (I missed those yesterday... ;)
Can you please update those (we do for other repos ;)?