summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaushik Lingarkar <kaushikl@qti.qualcomm.com>2024-12-17 12:49:14 -0800
committerKaushik Lingarkar <kaushikl@qti.qualcomm.com>2025-02-04 08:07:49 -0800
commitcf9a2a2a76b332c89fef40e47f7ddb4e8c817ab9 (patch)
treecfecbcec1354e04b5846706eb9b148ddc22c45dd
parent5ae8292fea94bc26aa8c7345f5230899d3d45a63 (diff)
downloadgit-repo-cf9a2a2a76b332c89fef40e47f7ddb4e8c817ab9.tar.gz
Update internal filesystem layout for submodules
Change the bare checkout directory for submodules from 'subprojects' to 'modules'. Git expects bare submodule checkouts to be in the 'modules' directory. If old subproject directories are found, they will be migrated to the new modules directory. This change is the first step in ensuring Git can understand repo's submodules to some extent. Change-Id: I385029f1bb55d040616d970d6ffb4bb856692520 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/444881 Tested-by: Kaushik Lingarkar <kaushikl@qti.qualcomm.com> Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
-rw-r--r--docs/internal-fs-layout.md2
-rw-r--r--manifest_xml.py7
-rw-r--r--project.py27
3 files changed, 34 insertions, 2 deletions
diff --git a/docs/internal-fs-layout.md b/docs/internal-fs-layout.md
index f63978f3..c0e44778 100644
--- a/docs/internal-fs-layout.md
+++ b/docs/internal-fs-layout.md
@@ -141,7 +141,7 @@ Instead, you should use standard Git workflows like [git worktree] or
141 (e.g. a local mirror & a public review server) while avoiding duplicating 141 (e.g. a local mirror & a public review server) while avoiding duplicating
142 the content. However, this can run into problems if different remotes use 142 the content. However, this can run into problems if different remotes use
143 the same path on their respective servers. Best to avoid that. 143 the same path on their respective servers. Best to avoid that.
144* `subprojects/`: Like `projects/`, but for git submodules. 144* `modules/`: Like `projects/`, but for git submodules.
145* `subproject-objects/`: Like `project-objects/`, but for git submodules. 145* `subproject-objects/`: Like `project-objects/`, but for git submodules.
146* `worktrees/`: Bare checkouts of every project synced by the manifest. The 146* `worktrees/`: Bare checkouts of every project synced by the manifest. The
147 filesystem layout matches the `<project name=...` setting in the manifest 147 filesystem layout matches the `<project name=...` setting in the manifest
diff --git a/manifest_xml.py b/manifest_xml.py
index cdab31e6..347ae5ef 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -2056,7 +2056,12 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
2056 path = path.rstrip("/") 2056 path = path.rstrip("/")
2057 name = name.rstrip("/") 2057 name = name.rstrip("/")
2058 relpath = self._JoinRelpath(parent.relpath, path) 2058 relpath = self._JoinRelpath(parent.relpath, path)
2059 gitdir = os.path.join(parent.gitdir, "subprojects", "%s.git" % path) 2059 subprojects = os.path.join(parent.gitdir, "subprojects", f"{path}.git")
2060 modules = os.path.join(parent.gitdir, "modules", path)
2061 if platform_utils.isdir(subprojects):
2062 gitdir = subprojects
2063 else:
2064 gitdir = modules
2060 objdir = os.path.join( 2065 objdir = os.path.join(
2061 parent.gitdir, "subproject-objects", "%s.git" % name 2066 parent.gitdir, "subproject-objects", "%s.git" % name
2062 ) 2067 )
diff --git a/project.py b/project.py
index de1ab3c6..b58bd53b 100644
--- a/project.py
+++ b/project.py
@@ -3415,6 +3415,11 @@ class Project:
3415 """ 3415 """
3416 dotgit = os.path.join(self.worktree, ".git") 3416 dotgit = os.path.join(self.worktree, ".git")
3417 3417
3418 # If bare checkout of the submodule is stored under the subproject dir,
3419 # migrate it.
3420 if self.parent:
3421 self._MigrateOldSubmoduleDir()
3422
3418 # If using an old layout style (a directory), migrate it. 3423 # If using an old layout style (a directory), migrate it.
3419 if not platform_utils.islink(dotgit) and platform_utils.isdir(dotgit): 3424 if not platform_utils.islink(dotgit) and platform_utils.isdir(dotgit):
3420 self._MigrateOldWorkTreeGitDir(dotgit, project=self.name) 3425 self._MigrateOldWorkTreeGitDir(dotgit, project=self.name)
@@ -3548,6 +3553,28 @@ class Project:
3548 dotgit, 3553 dotgit,
3549 ) 3554 )
3550 3555
3556 def _MigrateOldSubmoduleDir(self):
3557 """Move the old bare checkout in 'subprojects' to 'modules'
3558 as bare checkouts of submodules are now in 'modules' dir.
3559 """
3560 subprojects = os.path.join(self.parent.gitdir, "subprojects")
3561 if not platform_utils.isdir(subprojects):
3562 return
3563
3564 modules = os.path.join(self.parent.gitdir, "modules")
3565 old = self.gitdir
3566 new = os.path.splitext(self.gitdir.replace(subprojects, modules))[0]
3567
3568 if all(map(platform_utils.isdir, [old, new])):
3569 platform_utils.rmtree(old, ignore_errors=True)
3570 else:
3571 os.makedirs(modules, exist_ok=True)
3572 platform_utils.rename(old, new)
3573 self.gitdir = new
3574 self.UpdatePaths(self.relpath, self.worktree, self.gitdir, self.objdir)
3575 if platform_utils.isdir(subprojects) and not os.listdir(subprojects):
3576 platform_utils.rmtree(subprojects, ignore_errors=True)
3577
3551 def _get_symlink_error_message(self): 3578 def _get_symlink_error_message(self):
3552 if platform_utils.isWindows(): 3579 if platform_utils.isWindows():
3553 return ( 3580 return (