Skip to contentSkip to conversation

fetch2/git: Simplify the validation of SHA-1 revisions

PATCH Superseded Peter Kjellerstedt 3 participants 3 messages Apr 14, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2/git: Simplify the validation of SHA-1 revisions

Also correct two comments.

---
 bitbake/lib/bb/fetch2/git.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
bitbake/lib/bb/fetch2/git.py +6 -5
index b3eb8248d0..90104ac383 100644
@@ -248,9 +248,10 @@ class Git(FetchMethod):
 
         ud.setup_revisions(d)
 
+        sha1_re = re.compile(r'^[0-9a-f]{40}$')
         for name in ud.names:
-            # Ensure anything that doesn't look like a sha256 checksum/revision is translated into one
-            if not ud.revisions[name] or len(ud.revisions[name]) != 40  or (False in [c in "abcdef0123456789" for c in ud.revisions[name]]):
+            # Ensure any revision that doesn't look like a SHA-1 is translated into one
+            if not sha1_re.match(ud.revisions[name] or ''):
                 if ud.revisions[name]:
                     ud.unresolvedrev[name] = ud.revisions[name]
                 ud.revisions[name] = self.latest_revision(ud, d, name)
@@ -259,10 +260,10 @@ class Git(FetchMethod):
         if gitsrcname.startswith('.'):
             gitsrcname = gitsrcname[1:]
 
-        # for rebaseable git repo, it is necessary to keep mirror tar ball
-        # per revision, so that even the revision disappears from the
+        # For a rebaseable git repo, it is necessary to keep a mirror tar ball
+        # per revision, so that even if the revision disappears from the
         # upstream repo in the future, the mirror will remain intact and still
-        # contains the revision
+        # contain the revision
         if ud.rebaseable:
             for name in ud.names:
                 gitsrcname = gitsrcname + '_' + ud.revisions[name]
#1 lore raw
Quoted 12 lines · Peter Kjellerstedt

Also correct two comments.

---
 bitbake/lib/bb/fetch2/git.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
bitbake/lib/bb/fetch2/git.py +0 -0
index b3eb8248d0..90104ac383 100644

bitbake/lib/bb/fetch2/git.py class Git(FetchMethod): · line 251

Quoted 4 lines
bitbake/lib/bb/fetch2/git.py +1 -0
@@ -248,9 +248,10 @@ class Git(FetchMethod):
 
         ud.setup_revisions(d)
 
+        sha1_re = re.compile(r'^[0-9a-f]{40}$')

re.compile() is expensive so in general we should cache that or do it at the module top level...

Cheers,

Richard

#2 lore raw
Quoted 22 lines

-----Original Message-----
From: Richard Purdie <[email protected]>
Sent: den 14 april 2022 18:28
To: Peter Kjellerstedt <[email protected]>; bitbake- [email protected]
Subject: Re: [bitbake-devel] [PATCH] fetch2/git: Simplify the validation of SHA-1 revisions

Quoted 13 lines · Peter Kjellerstedt

Also correct two comments.

---
 bitbake/lib/bb/fetch2/git.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
bitbake/lib/bb/fetch2/git.py +0 -0
index b3eb8248d0..90104ac383 100644
@@ -248,9 +248,10 @@ class Git(FetchMethod):
 
Quoted 6 lines

bitbake/lib/bb/fetch2/git.py class Git(FetchMethod): · line 251

Quoted 3 lines
bitbake/lib/bb/fetch2/git.py +1 -0
         ud.setup_revisions(d)
 
+        sha1_re = re.compile(r'^[0-9a-f]{40}$')

re.compile() is expensive so in general we should cache that or do it at the module top level...

Sure, I can move it to the module top level.

I based the use of re.compile() in that class on how it was done in the _revision_key() function. Do you want me to move its slash_re as well?

Quoted 3 lines

Cheers,

Richard

//Peter