[bitbake-devel] [PATCH] fetch2/gitsm.py: Change the URI construction logic

Mark Hatle mark.hatle at windriver.com
Thu Dec 20 18:05:13 UTC 2018


This looks like a reasonable way to handle the different URL types.

--Mark

On 12/20/18 4:23 AM, Krystian Garliński wrote:
> 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 <krystian.garlinski at comarch.pl>
> ---
>  lib/bb/fetch2/gitsm.py | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/bb/fetch2/gitsm.py b/lib/bb/fetch2/gitsm.py
> index 35729dbc..59828355 100644
> --- a/lib/bb/fetch2/gitsm.py
> +++ b/lib/bb/fetch2/gitsm.py
> @@ -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"
> 



More information about the bitbake-devel mailing list