summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/git.py
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2022-04-14 22:37:27 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-04-19 14:15:09 +0100
commit51ed090de1a82b01904742401edb06724f9c8177 (patch)
treea518e87ad45b8cb59ff6b9669172b55f0b5aa16c /bitbake/lib/bb/fetch2/git.py
parent57b11d17247c626e97c5eabc4343dd89b0765c87 (diff)
downloadpoky-51ed090de1a82b01904742401edb06724f9c8177.tar.gz
bitbake: fetch2/git: Simplify the validation of SHA-1 revisions
Also correct two comments, and move slash_re from _revision_key() to the module top level (together with the new sha1_re). (Bitbake rev: 98cad8636e9c82bc40a033bb83633ec994758eb0) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r--bitbake/lib/bb/fetch2/git.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index b3eb8248d0..bdcfa4978c 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -74,6 +74,9 @@ from bb.fetch2 import runfetchcmd
74from bb.fetch2 import logger 74from bb.fetch2 import logger
75 75
76 76
77sha1_re = re.compile(r'^[0-9a-f]{40}$')
78slash_re = re.compile(r"/+")
79
77class GitProgressHandler(bb.progress.LineFilterProgressHandler): 80class GitProgressHandler(bb.progress.LineFilterProgressHandler):
78 """Extract progress information from git output""" 81 """Extract progress information from git output"""
79 def __init__(self, d): 82 def __init__(self, d):
@@ -249,8 +252,8 @@ class Git(FetchMethod):
249 ud.setup_revisions(d) 252 ud.setup_revisions(d)
250 253
251 for name in ud.names: 254 for name in ud.names:
252 # Ensure anything that doesn't look like a sha256 checksum/revision is translated into one 255 # Ensure any revision that doesn't look like a SHA-1 is translated into one
253 if not ud.revisions[name] or len(ud.revisions[name]) != 40 or (False in [c in "abcdef0123456789" for c in ud.revisions[name]]): 256 if not sha1_re.match(ud.revisions[name] or ''):
254 if ud.revisions[name]: 257 if ud.revisions[name]:
255 ud.unresolvedrev[name] = ud.revisions[name] 258 ud.unresolvedrev[name] = ud.revisions[name]
256 ud.revisions[name] = self.latest_revision(ud, d, name) 259 ud.revisions[name] = self.latest_revision(ud, d, name)
@@ -259,10 +262,10 @@ class Git(FetchMethod):
259 if gitsrcname.startswith('.'): 262 if gitsrcname.startswith('.'):
260 gitsrcname = gitsrcname[1:] 263 gitsrcname = gitsrcname[1:]
261 264
262 # for rebaseable git repo, it is necessary to keep mirror tar ball 265 # For a rebaseable git repo, it is necessary to keep a mirror tar ball
263 # per revision, so that even the revision disappears from the 266 # per revision, so that even if the revision disappears from the
264 # upstream repo in the future, the mirror will remain intact and still 267 # upstream repo in the future, the mirror will remain intact and still
265 # contains the revision 268 # contain the revision
266 if ud.rebaseable: 269 if ud.rebaseable:
267 for name in ud.names: 270 for name in ud.names:
268 gitsrcname = gitsrcname + '_' + ud.revisions[name] 271 gitsrcname = gitsrcname + '_' + ud.revisions[name]
@@ -697,7 +700,6 @@ class Git(FetchMethod):
697 Return a unique key for the url 700 Return a unique key for the url
698 """ 701 """
699 # Collapse adjacent slashes 702 # Collapse adjacent slashes
700 slash_re = re.compile(r"/+")
701 return "git:" + ud.host + slash_re.sub(".", ud.path) + ud.unresolvedrev[name] 703 return "git:" + ud.host + slash_re.sub(".", ud.path) + ud.unresolvedrev[name]
702 704
703 def _lsremote(self, ud, d, search): 705 def _lsremote(self, ud, d, search):