summaryrefslogtreecommitdiffstats
path: root/manifest_xml.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-02-09 02:28:34 -0500
committerMike Frysinger <vapier@google.com>2020-02-19 18:11:33 +0000
commit979d5bdc3ebe45998a76dbbaff46c33d4e59683b (patch)
tree97c639570a60dd02a6ee9b712dff091a83ac8110 /manifest_xml.py
parent56ce3468b4f2faa1cccfea01dc91e7db73fb3843 (diff)
downloadgit-repo-979d5bdc3ebe45998a76dbbaff46c33d4e59683b.tar.gz
add experimental git worktree support
This provides initial support for using git worktrees internally instead of our own ad-hoc symlink tree. It's been lightly tested which is why it's not currently exposed via --help. When people opt-in to worktrees in an existing repo client checkout, no projects are migrated. Instead, only new projects will use the worktree method. This allows for limited testing/opting in without having to completely blow things away or get a second checkout. Bug: https://crbug.com/gerrit/11486 Change-Id: Ic3ff891b30940a6ba497b406b2a387e0a8517ed8 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254075 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'manifest_xml.py')
-rw-r--r--manifest_xml.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/manifest_xml.py b/manifest_xml.py
index 7f38d8c3..41628003 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -146,9 +146,17 @@ class XmlManifest(object):
146 gitdir=os.path.join(repodir, 'repo/.git'), 146 gitdir=os.path.join(repodir, 'repo/.git'),
147 worktree=os.path.join(repodir, 'repo')) 147 worktree=os.path.join(repodir, 'repo'))
148 148
149 self.manifestProject = MetaProject(self, 'manifests', 149 mp = MetaProject(self, 'manifests',
150 gitdir=os.path.join(repodir, 'manifests.git'), 150 gitdir=os.path.join(repodir, 'manifests.git'),
151 worktree=os.path.join(repodir, 'manifests')) 151 worktree=os.path.join(repodir, 'manifests'))
152 self.manifestProject = mp
153
154 # This is a bit hacky, but we're in a chicken & egg situation: all the
155 # normal repo settings live in the manifestProject which we just setup
156 # above, so we couldn't easily query before that. We assume Project()
157 # init doesn't care if this changes afterwards.
158 if mp.config.GetBoolean('repo.worktree'):
159 mp.use_git_worktrees = True
152 160
153 self._Unload() 161 self._Unload()
154 162
@@ -428,6 +436,10 @@ class XmlManifest(object):
428 return self.manifestProject.config.GetBoolean('repo.mirror') 436 return self.manifestProject.config.GetBoolean('repo.mirror')
429 437
430 @property 438 @property
439 def UseGitWorktrees(self):
440 return self.manifestProject.config.GetBoolean('repo.worktree')
441
442 @property
431 def IsArchive(self): 443 def IsArchive(self):
432 return self.manifestProject.config.GetBoolean('repo.archive') 444 return self.manifestProject.config.GetBoolean('repo.archive')
433 445
@@ -873,8 +885,10 @@ class XmlManifest(object):
873 groups = self._ParseGroups(groups) 885 groups = self._ParseGroups(groups)
874 886
875 if parent is None: 887 if parent is None:
876 relpath, worktree, gitdir, objdir = self.GetProjectPaths(name, path) 888 relpath, worktree, gitdir, objdir, use_git_worktrees = \
889 self.GetProjectPaths(name, path)
877 else: 890 else:
891 use_git_worktrees = False
878 relpath, worktree, gitdir, objdir = \ 892 relpath, worktree, gitdir, objdir = \
879 self.GetSubprojectPaths(parent, name, path) 893 self.GetSubprojectPaths(parent, name, path)
880 894
@@ -903,6 +917,7 @@ class XmlManifest(object):
903 upstream=upstream, 917 upstream=upstream,
904 parent=parent, 918 parent=parent,
905 dest_branch=dest_branch, 919 dest_branch=dest_branch,
920 use_git_worktrees=use_git_worktrees,
906 **extra_proj_attrs) 921 **extra_proj_attrs)
907 922
908 for n in node.childNodes: 923 for n in node.childNodes:
@@ -918,6 +933,7 @@ class XmlManifest(object):
918 return project 933 return project
919 934
920 def GetProjectPaths(self, name, path): 935 def GetProjectPaths(self, name, path):
936 use_git_worktrees = False
921 relpath = path 937 relpath = path
922 if self.IsMirror: 938 if self.IsMirror:
923 worktree = None 939 worktree = None
@@ -926,8 +942,15 @@ class XmlManifest(object):
926 else: 942 else:
927 worktree = os.path.join(self.topdir, path).replace('\\', '/') 943 worktree = os.path.join(self.topdir, path).replace('\\', '/')
928 gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path) 944 gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path)
929 objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name) 945 # We allow people to mix git worktrees & non-git worktrees for now.
930 return relpath, worktree, gitdir, objdir 946 # This allows for in situ migration of repo clients.
947 if os.path.exists(gitdir) or not self.UseGitWorktrees:
948 objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name)
949 else:
950 use_git_worktrees = True
951 gitdir = os.path.join(self.repodir, 'worktrees', '%s.git' % name)
952 objdir = gitdir
953 return relpath, worktree, gitdir, objdir, use_git_worktrees
931 954
932 def GetProjectsWithName(self, name): 955 def GetProjectsWithName(self, name):
933 return self._projects.get(name, []) 956 return self._projects.get(name, [])