fetch2/gitsm.py: Change the URI construction logic
PATCH 1/1 fetch2/gitsm.py: Change the URI construction logic
Git allows to use both the proper URI's and SCP-like short style syntax for the SSH protocol. This commit changes construction logic to detect which one of the two is used in the submodule specification and to build a correct URI out of it.
--- lib/bb/fetch2/gitsm.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
lib/bb/fetch2/gitsm.py +17 -2
@@ -32,6 +32,9 @@ NOTE: Switching a SRC_URI from "git://" to "gitsm://" requires a clean of your r import os import bb import copy +import re +from urllib.parse import urlparse +from urllib.parse import urlunparse from bb.fetch2.git import Git from bb.fetch2 import runfetchcmd from bb.fetch2 import logger
@@ -39,6 +42,8 @@ from bb.fetch2 import Fetch from bb.fetch2 import BBFetchException class GitSM(Git): + scp_regex = re.compile(r'^([a-zA-Z0-9_]+)@([a-zA-Z0-9._-]+):(.+)$') + def supports(self, ud, d): """ Check to see if a given url can be fetched with git.
@@ -88,8 +93,18 @@ class GitSM(Git): module_hash = module_hash.split()[2] # Build new SRC_URI - proto = uris[module].split(':', 1)[0] - url = uris[module].replace('%s:' % proto, 'gitsm:', 1) + uri = uris[module] + match = GitSM.scp_regex.match(uri) + + if match: + # this URI follows the short SCP-like syntax + url = 'gitsm://{}@{}/{}'.format(match.group(1), match.group(2), match.group(3)) + proto = 'ssh' + else: + result = urlparse(uris[module], scheme='ssh') + proto = result.scheme + url = urlunparse(result._replace(scheme='gitsm')) + url += ';protocol=%s' % proto url += ";name=%s" % module url += ";bareclone=1;nocheckout=1;nobranch=1"
Signature · 1 line
2.19.1
This looks like a reasonable way to handle the different URL types.
--Mark
Quoted 55 lines · Krystian Garliński
Git allows to use both the proper URI's and SCP-like short style syntax for the SSH protocol. This commit changes construction logic to detect which one of the two is used in the submodule specification and to build a correct URI out of it.
Signed-off-by Krystian Garliński <[email protected]>--- lib/bb/fetch2/gitsm.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)lib/bb/fetch2/gitsm.py +17
-2@@ -32,6 +32,9 @@ NOTE: Switching a SRC_URI from "git://" to "gitsm://" requires a clean of your r import os import bb import copy +import re +from urllib.parse import urlparse +from urllib.parse import urlunparse from bb.fetch2.git import Git from bb.fetch2 import runfetchcmd from bb.fetch2 import logger@@ -39,6 +42,8 @@ from bb.fetch2 import Fetch from bb.fetch2 import BBFetchException class GitSM(Git): + scp_regex = re.compile(r'^([a-zA-Z0-9_]+)@([a-zA-Z0-9._-]+):(.+)$') + def supports(self, ud, d): """ Check to see if a given url can be fetched with git.@@ -88,8 +93,18 @@ class GitSM(Git): module_hash = module_hash.split()[2] # Build new SRC_URI - proto = uris[module].split(':', 1)[0] - url = uris[module].replace('%s:' % proto, 'gitsm:', 1) + uri = uris[module] + match = GitSM.scp_regex.match(uri) + + if match: + # this URI follows the short SCP-like syntax + url = 'gitsm://{}@{}/{}'.format(match.group(1), match.group(2), match.group(3)) + proto = 'ssh' + else: + result = urlparse(uris[module], scheme='ssh') + proto = result.scheme + url = urlunparse(result._replace(scheme='gitsm')) + url += ';protocol=%s' % proto url += ";name=%s" % module url += ";bareclone=1;nocheckout=1;nobranch=1"
Quoted 8 lines · Krystian Garliński
Git allows to use both the proper URI's and SCP-like short style syntax
for the SSH protocol. This commit changes construction logic to detect which
one of the two is used in the submodule specification and to build a correct
URI out of it.
Quoted 4 lines
Signed-off-by Krystian Garliński <[email protected]>--- lib/bb/fetch2/gitsm.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
This causes bitbake-selftest to fail:
$ bitbake-selftest
..................................................................................................................................................................................................................................................................................................................E
Stdout:
Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 ls-remote file:///tmp/tmp96d_f_w2/gitsource
Trying PREMIRRORS
Trying Upstream
Running export PSEUDO_DISABLED=1; LANG=C git -c core.fsyncobjectfiles=0 clone --bare --mirror /tmp/tmp96d_f_w2/gitsource /tmp/tmp96d_f_w2/download/git2/tmp.tmp96d_f_w2.gitsource --progress
Cloning into bare repository '/tmp/tmp96d_f_w2/download/git2/tmp.tmp96d_f_w2.gitsource'...
done.
Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 branch --contains b9f67d0efd04c6a57ac03c7b76166d76e2b46972 --list master 2> /dev/null | wc -l
Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 branch --contains b9f67d0efd04c6a57ac03c7b76166d76e2b46972 --list master 2> /dev/null | wc -l
Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 show b9f67d0efd04c6a57ac03c7b76166d76e2b46972:.gitmodules
Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 ls-tree -z -d b9f67d0efd04c6a57ac03c7b76166d76e2b46972 gitsubmodule
Failed to fetch URL gitsm:///tmp/tmp96d_f_w2/gitsource;protocol=file;subdir=/tmp/tmp96d_f_w2/git, attempting MIRRORS if available
The URL: 'gitsm:/tmp/tmp96d_f_w2/gitsubmodule;protocol=file;name=gitsubmodule;bareclone=1;nocheckout=1;nobranch=1' is invalid and cannot be interpreted
Trying MIRRORS
The URL: 'gitsm:/tmp/tmp96d_f_w2/gitsubmodule;protocol=file;name=gitsubmodule;bareclone=1;nocheckout=1;nobranch=1' is invalid and cannot be interpreted
...........................................................................
======================================================================
ERROR: test_shallow_submodules (bb.tests.fetch.GitShallowTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/media/build1/poky/bitbake/lib/bb/tests/fetch.py", line 1476, in test_shallow_submodules
fetcher, ud = self.fetch_shallow(uri)
File "/media/build1/poky/bitbake/lib/bb/tests/fetch.py", line 1305, in fetch_shallow
fetcher, ud = self.fetch_and_unpack(uri)
File "/media/build1/poky/bitbake/lib/bb/tests/fetch.py", line 1298, in fetch_and_unpack
fetcher, ud = self.fetch(uri)
File "/media/build1/poky/bitbake/lib/bb/tests/fetch.py", line 1293, in fetch
fetcher.download()
File "/media/build1/poky/bitbake/lib/bb/fetch2/__init__.py", line 1714, in download
raise FetchError("Unable to fetch URL from any source.", u)
bb.fetch2.FetchError: Fetcher failure for URL: 'gitsm:///tmp/tmp96d_f_w2/gitsource;protocol=file;subdir=/tmp/tmp96d_f_w2/git'. Unable to fetch URL from any source.Stdout:
Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 ls-remote file:///tmp/tmp96d_f_w2/gitsource
Trying PREMIRRORS
Trying Upstream
Running export PSEUDO_DISABLED=1; LANG=C git -c core.fsyncobjectfiles=0 clone --bare --mirror /tmp/tmp96d_f_w2/gitsource /tmp/tmp96d_f_w2/download/git2/tmp.tmp96d_f_w2.gitsource --progress Cloning into bare repository '/tmp/tmp96d_f_w2/download/git2/tmp.tmp96d_f_w2.gitsource'...
done.
Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 branch --contains b9f67d0efd04c6a57ac03c7b76166d76e2b46972 --list master 2> /dev/null | wc -l Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 branch --contains b9f67d0efd04c6a57ac03c7b76166d76e2b46972 --list master 2> /dev/null | wc -l Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 show b9f67d0efd04c6a57ac03c7b76166d76e2b46972:.gitmodules
Running export PSEUDO_DISABLED=1; git -c core.fsyncobjectfiles=0 ls-tree -z -d b9f67d0efd04c6a57ac03c7b76166d76e2b46972 gitsubmodule
Failed to fetch URL gitsm:///tmp/tmp96d_f_w2/gitsource;protocol=file;subdir=/tmp/tmp96d_f_w2/git, attempting MIRRORS if available
The URL: 'gitsm:/tmp/tmp96d_f_w2/gitsubmodule;protocol=file;name=gitsubmodule;bareclone=1;nocheckout=1;nobranch=1' is invalid and cannot be interpreted Trying MIRRORS
The URL: 'gitsm:/tmp/tmp96d_f_w2/gitsubmodule;protocol=file;name=gitsubmodule;bareclone=1;nocheckout=1;nobranch=1' is invalid and cannot be interpreted
----------------------------------------------------------------------
Ran 382 tests in 477.872s
FAILED (errors=1)