Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/utils.py
# Copyright (C) 2017-2021 The Software Heritage developers | # Copyright (C) 2017-2021 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 | ||||
"""Utilities helper functions""" | """Utilities helper functions""" | ||||
import datetime | import datetime | ||||
import logging | import logging | ||||
import os | import os | ||||
import shutil | import shutil | ||||
import tempfile | import tempfile | ||||
from typing import Dict, NewType, Optional | from typing import Dict, Mapping, NewType, Optional, Union | ||||
from swh.core import tarball | from swh.core import tarball | ||||
from swh.model.model import SnapshotBranch | from swh.model.model import SnapshotBranch | ||||
# The hexadecimal representation of the hash in bytes | # The hexadecimal representation of the hash in bytes | ||||
HexBytes = NewType("HexBytes", bytes) | HexBytes = NewType("HexBytes", bytes) | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | if branch_name.endswith(b"^{}"): | ||||
return True | return True | ||||
elif branch_name.startswith(b"refs/pull/") and branch_name.endswith(b"/merge"): | elif branch_name.startswith(b"refs/pull/") and branch_name.endswith(b"/merge"): | ||||
# We filter-out auto-merged GitHub pull requests | # We filter-out auto-merged GitHub pull requests | ||||
return True | return True | ||||
return False | return False | ||||
def filter_refs(refs: Dict[bytes, bytes]) -> Dict[bytes, HexBytes]: | def filter_refs(refs: Mapping[bytes, Union[bytes, HexBytes]]) -> Dict[bytes, HexBytes]: | ||||
"""Filter the refs dictionary using the policy set in `ignore_branch_name`""" | """Filter the refs dictionary using the policy set in `ignore_branch_name`""" | ||||
return { | return { | ||||
name: HexBytes(target) | name: HexBytes(target) | ||||
for name, target in refs.items() | for name, target in refs.items() | ||||
if not ignore_branch_name(name) | if not ignore_branch_name(name) | ||||
} | } | ||||
Show All 22 Lines |