diff mbox series

[11/15] fetch2: gitsm: handle submodules inside submodule unpack

Message ID 20250902064515.30879-12-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series fetch2: gitsm: rework and simplify | expand

Commit Message

Stefan Herbrechtsmeier Sept. 2, 2025, 6:45 a.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Handle the git submodule setup inside the unpack function of the
submodule to simplify the loop.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

 lib/bb/fetch2/gitsm.py | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/gitsm.py b/lib/bb/fetch2/gitsm.py
index c3e7189a0..37f82cd37 100644
--- a/lib/bb/fetch2/gitsm.py
+++ b/lib/bb/fetch2/gitsm.py
@@ -198,25 +198,28 @@  class GitSM(Git):
         self.call_process_submodules(ud, d, self.need_update(ud, d), download_submodule)
 
     def unpack(self, ud, destdir, d):
-        subdestdir = self.destdir(ud, destdir, d)
+        fulldestdir = self.destdir(ud, destdir, d)
 
         def unpack_submodules(ud, url, module, modpath, workdir, d):
             try:
                 newfetch = Fetch([url], d, cache=False)
-                new_ud = newfetch.ud[url]
-                parentdir = new_ud.parm['parentdir']
-                if not os.path.isabs(parentdir):
-                    parentdir = os.path.join(destdir, parentdir)
-                fulldestdir = self.destdir(new_ud, destdir, d)
                 newfetch.unpack(root=destdir)
             except Exception as e:
                 logger.error('gitsm: submodule unpack failed: %s %s' % (type(e).__name__, str(e)))
                 raise
 
-            local_path = newfetch.localpath(url)
+        Git.unpack(self, ud, destdir, d)
+
+        parentdir = ud.parm.get('parentdir')
+        if parentdir:
+            module = ud.parm['subpath']
+            if not os.path.isabs(parentdir):
+                parentdir = os.path.join(destdir, parentdir)
+
+            ud.setup_localpath(d)
 
             # 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_path}, d, workdir=parentdir)
+            runfetchcmd("%(basecmd)s config submodule.%(module)s.url %(url)s" % {'basecmd': ud.basecmd, 'module': module, 'url' : ud.localpath}, d, workdir=parentdir)
 
             if ud.shallow:
                 runfetchcmd("%(basecmd)s config submodule.%(module)s.shallow true" % {'basecmd': ud.basecmd, 'module': module}, d, workdir=parentdir)
@@ -228,16 +231,14 @@  class GitSM(Git):
                 logger.error("Unable to set git config core.bare to false for %s" % fulldestdir)
                 raise
 
-        Git.unpack(self, ud, destdir, d)
-
-        ret = self.process_submodules(ud, subdestdir, unpack_submodules, d)
+        ret = self.process_submodules(ud, fulldestdir, unpack_submodules, d)
 
         if not ud.bareclone and ret:
             cmdprefix = ""
             # Avoid LFS smudging (replacing the LFS pointers with the actual content) when LFS shouldn't be used but git-lfs is installed.
             if not self._need_lfs(ud):
                 cmdprefix = "GIT_LFS_SKIP_SMUDGE=1 "
-            runfetchcmd("%s%s submodule update --recursive --no-fetch" % (cmdprefix, ud.basecmd), d, quiet=True, workdir=subdestdir)
+            runfetchcmd("%s%s submodule update --recursive --no-fetch" % (cmdprefix, ud.basecmd), d, quiet=True, workdir=fulldestdir)
     def clean(self, ud, d):
         def clean_submodule(ud, url, module, modpath, workdir, d):
             try: