Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/utils.py
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | 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 ignore_branch_name(branch_name: bytes) -> bool: | |||||
"""Should the git loader ignore the branch named `branch_name`?""" | |||||
if branch_name.endswith(b"^{}"): | |||||
# Peeled refs make the git protocol explode | |||||
return True | |||||
elif branch_name.startswith(b"refs/pull/") and branch_name.endswith(b"/merge"): | |||||
# We filter-out auto-merged GitHub pull requests | |||||
return True | |||||
return False | |||||
def filter_refs(refs: Dict[bytes, bytes]) -> Dict[bytes, bytes]: | |||||
"""Filter the refs dictionary using the policy set in `ignore_branch_name`""" | |||||
return { | |||||
name: target for name, target in refs.items() if not ignore_branch_name(name) | |||||
} | |||||
def warn_dangling_branches( | def warn_dangling_branches( | ||||
branches: Dict[bytes, Optional[SnapshotBranch]], | branches: Dict[bytes, Optional[SnapshotBranch]], | ||||
dangling_branches: Dict[bytes, bytes], | dangling_branches: Dict[bytes, bytes], | ||||
logger: logging.Logger, | logger: logging.Logger, | ||||
origin_url: str, | origin_url: str, | ||||
) -> None: | ) -> None: | ||||
dangling_branches = { | dangling_branches = { | ||||
target: ref for target, ref in dangling_branches.items() if not branches[target] | target: ref for target, ref in dangling_branches.items() if not branches[target] | ||||
Show All 14 Lines |