From 9818e623be3aad1b325975e0ce7affd84920a757 Mon Sep 17 00:00:00 2001 From: James Frost Date: Fri, 4 Sep 2026 12:55:47 +0100 Subject: [PATCH] Support SHA-256 git hashes in reference checks Git 3.0 will be defaulting to SHA-256, so will have longer (64 character) object IDs. This is a non-exhaustive fix, as I have not checked everywhere in the codebase, but just grepped for some common regex patterns that would be problematic. I have checked that you can checkout a SHA-256 format repository though. --- github_scripts/get_git_sources.py | 5 ++++- github_scripts/git_bdiff.py | 4 ++-- github_scripts/suite_report_git.py | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/github_scripts/get_git_sources.py b/github_scripts/get_git_sources.py index 883fd635..90169f57 100644 --- a/github_scripts/get_git_sources.py +++ b/github_scripts/get_git_sources.py @@ -23,6 +23,9 @@ logger = logging.getLogger(__name__) +# Match hex commit IDs for both SHA-1 and SHA-256 repositories. +_hash_pattern = re.compile(r"^\s*([0-9a-f]{40}(?:[0-9a-f]{24})?)\s*") + class SubprocessRunError(Exception): def __init__(self, command, returncode, stdout, stderr): @@ -351,7 +354,7 @@ def determine_mirror_fetch(repo_source: str, repo_ref: str) -> str: # If the ref is a hash then we don't need the fork user as part of the fetch. # Equally, if the user is the Upstream User, it's not needed - if not user or re.match(r"^\s*([0-9a-f]{40})\s*$", repo_ref): + if not user or re.match(_hash_pattern, repo_ref): fetch = repo_ref else: fetch = f"{user}/{repo_ref}" diff --git a/github_scripts/git_bdiff.py b/github_scripts/git_bdiff.py index 2db51ddf..0836e27d 100644 --- a/github_scripts/git_bdiff.py +++ b/github_scripts/git_bdiff.py @@ -111,8 +111,8 @@ class GitBDiff(GitBase): # Name of primary branch - default is main primary_branch = "main" - # Match hex commit IDs - _hash_pattern = re.compile(r"^\s*([0-9a-f]{40})\s*$") + # Match hex commit IDs for both SHA-1 and SHA-256 repositories. + _hash_pattern = re.compile(r"^\s*([0-9a-f]{40}(?:[0-9a-f]{24})?)\s*") def __init__(self, parent=None, repo=None): self.parent = parent or self.primary_branch diff --git a/github_scripts/suite_report_git.py b/github_scripts/suite_report_git.py index 62dc2b8e..34320f3c 100755 --- a/github_scripts/suite_report_git.py +++ b/github_scripts/suite_report_git.py @@ -20,6 +20,9 @@ from suite_data import SuiteData +# Match hex commit IDs for both SHA-1 and SHA-256 repositories. +_hash_pattern = re.compile(r"^\s*([0-9a-f]{40}(?:[0-9a-f]{24})?)\s*") + def create_markdown_row(*columns: str, header=False) -> List[str]: """ @@ -151,7 +154,7 @@ def create_dependency_table(self) -> None: org_repo = extract_org_repo(reference) # Check if the ref is a hash and use short form if so - if re.match(r"^\s*([0-9a-f]{40})\s*$", ref): + if re.match(_hash_pattern, ref): ref = ref[:7] url = f"https://github.com/{org_repo}/tree/{ref}" reference = f"[{org_repo}@{ref}]({url})"