Skip to contentSkip to conversation

fetch2/gitsm: fix a typo

PATCH New Laurent Bonnans 1 participant 3 messages Oct 1, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 fetch2/gitsm: fix a typo

'qbareclone' in place of 'bareclone'

---
 lib/bb/fetch2/gitsm.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/fetch2/gitsm.py +1 -1
index 51f8d0e6..0cdc8301 100644
@@ -78,7 +78,7 @@ class GitSM(Git):
             url = uris[module].replace('%s:' % proto, 'gitsm:', 1)
             url += ';protocol=%s' % proto
             url += ";name=%s" % module
-            url += ";qbareclone=1;nocheckout=1"
+            url += ";bareclone=1;nocheckout=1"
 
             ld = d.createCopy()
             # Not necessary to set SRC_URI, since we're passing the URI to
Signature · 1 line
2.19.0
#1 lore raw

PATCH 2/3 fetch2/gitsm: handle submodules nested inside subdirs

The new gitsm fetcher assumed that submodules were living directly in the 'modules' directory, whereas they can be arbitrarily nested inside subdirectories.

Solve it by first creating the parent of the destination directory for the symlink and copy steps.

---
 lib/bb/fetch2/gitsm.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
lib/bb/fetch2/gitsm.py +9 -6
index 0cdc8301..fd5089c0 100644
@@ -98,12 +98,14 @@ class GitSM(Git):
 
             # Correct the submodule references to the local download version...
             runfetchcmd("%(basecmd)s config submodule.%(module)s.url %(url)s" % {'basecmd': ud.basecmd, 'module': module, 'url' : local_paths[module]}, d, workdir=ud.clonedir)
-            try:
-                os.mkdir(os.path.join(ud.clonedir, 'modules'))
-            except OSError:
-                pass
-            if not os.path.exists(os.path.join(ud.clonedir, 'modules', paths[module])):
-                os.symlink(local_paths[module], os.path.join(ud.clonedir, 'modules', paths[module]))
+
+            symlink_path = os.path.join(ud.clonedir, 'modules', paths[module])
+            if not os.path.exists(symlink_path):
+                try:
+                    os.makedirs(os.path.dirname(symlink_path), exist_ok=True)
+                except OSError:
+                    pass
+                os.symlink(local_paths[module], symlink_path)
 
         return True
 
@@ -148,6 +150,7 @@ class GitSM(Git):
                 if os.path.exists(modpath):
                     target = os.path.dirname(modpath)
 
+                os.makedirs(os.path.dirname(target), exist_ok=True)
                 runfetchcmd("cp -fpLR %s %s" % (srcpath, target), d)
             elif os.path.exists(modpath):
                 # Module already exists, likely unpacked from a shallow mirror clone
Signature · 1 line
2.19.0
#2 lore raw

PATCH 3/3 fetch2/gitsm: checkout submodules recursively

In reply to Laurent Bonnans

The new fetcher did not run 'git submodule update' recursively.

---
 lib/bb/fetch2/gitsm.py | 68 +++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 30 deletions(-)
lib/bb/fetch2/gitsm.py +38 -30
index fd5089c0..4d3805a1 100644
@@ -44,6 +44,22 @@ class GitSM(Git):
         """
         return ud.type in ['gitsm']
 
+    @staticmethod
+    def parse_gitmodules(gitmodules):
+        modules = {}
+        module = ""
+        for line in gitmodules.splitlines():
+            if line.startswith('[submodule'):
+                module = line.split('"')[1]
+                modules[module] = {}
+            elif module and line.strip().startswith('path'):
+                path = line.split('=')[1].strip()
+                modules[module]['path'] = path
+            elif module and line.strip().startswith('url'):
+                url = line.split('=')[1].strip()
+                modules[module]['url'] = url
+        return modules
+
     def update_submodules(self, ud, d):
         submodules = []
         paths = {}
@@ -57,17 +73,10 @@ class GitSM(Git):
                 # No submodules to update
                 continue
 
-            module = ""
-            for line in gitmodules.splitlines():
-                if line.startswith('[submodule'):
-                    module = line.split('"')[1]
-                    submodules.append(module)
-                elif module and line.strip().startswith('path'):
-                    path = line.split('=')[1].strip()
-                    paths[module] = path
-                elif module and line.strip().startswith('url'):
-                    url = line.split('=')[1].strip()
-                    uris[module] = url
+            for m, md in self.parse_gitmodules(gitmodules).items():
+                submodules.append(m)
+                paths[m] = md['path']
+                uris[m] = md['url']
 
         for module in submodules:
             module_hash = runfetchcmd("%s ls-tree -z -d %s %s" % (ud.basecmd, ud.revisions[name], paths[module]), d, quiet=True, workdir=ud.clonedir)
@@ -173,10 +182,7 @@ class GitSM(Git):
                 # No submodules to update
                 continue
 
-            for line in gitmodules.splitlines():
-                if line.startswith('[submodule'):
-                    module = line.split('"')[1]
-                    submodules.append(module)
+            submodules = list(self.parse_gitmodules(gitmodules).keys())
 
         self.copy_submodules(submodules, ud, dest, d)
 
@@ -200,23 +206,25 @@ class GitSM(Git):
                 # No submodules to update
                 continue
 
-            module = ""
-            for line in gitmodules.splitlines():
-                if line.startswith('[submodule'):
-                    module = line.split('"')[1]
-                    submodules.append(module)
-                elif module and line.strip().startswith('path'):
-                    path = line.split('=')[1].strip()
-                    paths[module] = path
-                elif module and line.strip().startswith('url'):
-                    url = line.split('=')[1].strip()
-                    uris[module] = url
+            for m, md in self.parse_gitmodules(gitmodules).items():
+                submodules.append(m)
+                paths[m] = md['path']
+                uris[m] = md['url']
 
         self.copy_submodules(submodules, ud, ud.destdir, d)
 
-        for module in submodules:
-            srcpath = os.path.join(ud.clonedir, 'modules', module)
-            modpath = os.path.join(repo_conf, 'modules', module)
+        submodules_queue = [(module, os.path.join(repo_conf, 'modules', module)) for module in submodules]
+        while len(submodules_queue) != 0:
+            module, modpath = submodules_queue.pop()
+
+            # add submodule children recursively
+            try:
+                gitmodules = runfetchcmd("%s show HEAD:.gitmodules" % (ud.basecmd), d, quiet=True, workdir=modpath)
+                for m, md in self.parse_gitmodules(gitmodules).items():
+                    submodules_queue.append([m, os.path.join(modpath, 'modules', m)])
+            except:
+                # no children
+                pass
 
             # Determine (from the submodule) the correct url to reference
             try:
@@ -235,4 +243,4 @@ class GitSM(Git):
 
         if submodules:
             # Run submodule update, this sets up the directories -- without touching the config
-            runfetchcmd("%s submodule update --no-fetch" % (ud.basecmd), d, quiet=True, workdir=ud.destdir)
+            runfetchcmd("%s submodule update --recursive --no-fetch" % (ud.basecmd), d, quiet=True, workdir=ud.destdir)
Signature · 1 line
2.19.0