diff mbox series

fetch2/gitsm: use configparser to parse .gitmodules

Message ID 20240910165804.2924480-1-ross.burton@arm.com
State New
Headers show
Series fetch2/gitsm: use configparser to parse .gitmodules | expand

Commit Message

Ross Burton Sept. 10, 2024, 4:58 p.m. UTC
.gitmodules is basically ini-style, so use configparser instead of manually
parsing by hand.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 bitbake/lib/bb/fetch2/gitsm.py | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/bitbake/lib/bb/fetch2/gitsm.py b/bitbake/lib/bb/fetch2/gitsm.py
index f7f3af72125..f193ae3c9ba 100644
--- a/bitbake/lib/bb/fetch2/gitsm.py
+++ b/bitbake/lib/bb/fetch2/gitsm.py
@@ -47,18 +47,20 @@  class GitSM(Git):
         subrevision = {}
 
         def parse_gitmodules(gitmodules):
+            """
+            Parse .gitmodules and return a dictionary of submodule paths to dictionaries with path and url members.
+            """
+            import configparser
+            cp = configparser.ConfigParser()
+            cp.read_string(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
+            for section in [s for s in cp.sections() if s.startswith("submodule ")]:
+                module = section.split('"')[1]
+                modules[module] = {
+                    'path': cp.get(section, 'path'),
+                    'url': cp.get(section, 'url')
+                }
             return modules
 
         # Collect the defined submodules, and their attributes