diff mbox series

[v2] fetch2: accept sha256 revisions

Message ID 20260618203918.1048412-2-mischief@offblast.org
State New
Headers show
Series [v2] fetch2: accept sha256 revisions | expand

Commit Message

Nick Owens June 18, 2026, 8:39 p.m. UTC
regexes in fetch2's git support currently don't allow for fetching git
repos with the sha256 object format.

to allow fetching sha256 git repos, adjust the regular expression and
fix all of the references.

tested on my gitea server with a sha256 repo

fixes https://bugzilla.yoctoproject.org/show_bug.cgi?id=16322

Signed-off-by: Nick Owens <mischief@offblast.org>
---
 bin/bitbake-setup    |  4 ++--
 lib/bb/fetch2/git.py | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index 2829e753e..c1963c55c 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -886,14 +886,14 @@  def get_diff(file1, file2):
 
 def are_layers_changed(layers, layerdir, d):
     def _is_git_remote_changed(r_remote, repodir):
-        from bb.fetch2.git import sha1_re
+        from bb.fetch2.git import git_hash_re
 
         rev = r_remote['rev']
         branch = r_remote.get('branch', None)
 
         rev_parse_result = bb.process.run(['git', '-C', os.path.join(layerdir, repodir), "rev-parse", "HEAD"])
         local_revision = rev_parse_result[0].strip()
-        if sha1_re.match(rev):
+        if git_hash_re.match(rev):
             if rev != local_revision:
                 logger.info('Layer repository checked out into {} is at revision {} but should be at {}'.format(os.path.join(layerdir, repodir),local_revision, rev))
                 return True
diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index cd045a3a9..0fbd85441 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -82,7 +82,7 @@  from   bb.fetch2 import logger
 from   bb.fetch2 import trusted_network
 
 
-sha1_re = re.compile(r'^[0-9a-f]{40}$')
+git_hash_re = re.compile(r'^[0-9a-f]{40,64}$')
 slash_re = re.compile(r"/+")
 
 class GitProgressHandler(bb.progress.LineFilterProgressHandler):
@@ -257,8 +257,8 @@  class Git(FetchMethod):
 
         ud.setup_revisions(d)
 
-        # Ensure any revision that doesn't look like a SHA-1 is translated into one
-        if not sha1_re.match(ud.revision or ''):
+        # Ensure any revision that doesn't look like a git hash (SHA-1 or SHA-256) is resolved
+        if not git_hash_re.match(ud.revision or ''):
             if ud.revision:
                 ud.unresolvedrev = ud.revision
             ud.revision = self.latest_revision(ud, d, ud.name)
@@ -752,7 +752,7 @@  class Git(FetchMethod):
 
         # If there is a tag parameter in the url and we also have a fixed srcrev, check the tag
         # matches the revision
-        if 'tag' in ud.parm and sha1_re.match(ud.revision):
+        if 'tag' in ud.parm and git_hash_re.match(ud.revision):
             output = runfetchcmd(ud.basecmd + ['rev-list', '-n', '1', ud.parm['tag']], d, workdir=destdir, extraenv=extraenv)
             output = output.strip()
             if output != ud.revision:
@@ -976,7 +976,7 @@  class Git(FetchMethod):
             bb.note("Could not list remote: %s" % str(e))
             return pupver
 
-        rev_tag_re = re.compile(r"([0-9a-f]{40})\s+refs/tags/(.*)")
+        rev_tag_re = re.compile(r"([0-9a-f]{40,64})\s+refs/tags/(.*)")
         pver_re = re.compile(d.getVar('UPSTREAM_CHECK_GITTAGREGEX') or r"(?P<pver>([0-9][\.|_]?)+)")
         nonrel_re = re.compile(r"(alpha|beta|rc|final)+")