diff --git a/manifest_xml.py b/manifest_xml.py index 3c43295e3..db7a92865 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -768,8 +768,11 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md @property def is_multimanifest(self): - """Whether this is a multimanifest checkout""" - return bool(self.outer_client.submanifests) + """Whether this is a multimanifest checkout. + + This is safe to use as long as the outermost manifest XML has been parsed. + """ + return bool(self._outer_client._submanifests) @property def is_submanifest(self): @@ -1679,7 +1682,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md # We allow people to mix git worktrees & non-git worktrees for now. # This allows for in situ migration of repo clients. if os.path.exists(gitdir) or not self.UseGitWorktrees: - objdir = os.path.join(self.subdir, 'project-objects', namepath) + objdir = os.path.join(self.repodir, 'project-objects', namepath) else: use_git_worktrees = True gitdir = os.path.join(self.repodir, 'worktrees', namepath) diff --git a/project.py b/project.py index b7ed6f336..faa6b32b1 100644 --- a/project.py +++ b/project.py @@ -49,6 +49,9 @@ MAXIMUM_RETRY_SLEEP_SEC = 3600.0 # +-10% random jitter is added to each Fetches retry sleep duration. RETRY_JITTER_PERCENT = 0.1 +# Whether to use alternates. +# TODO(vapier): Remove knob once behavior is verified. +_ALTERNATES = os.environ.get('REPO_USE_ALTERNATES') == '1' def _lwrite(path, content): lock = '%s.lock' % path @@ -460,7 +463,7 @@ class RemoteSpec(object): class Project(object): # These objects can be shared between several working trees. - shareable_dirs = ['hooks', 'objects', 'rr-cache'] + shareable_dirs = ['hooks', 'rr-cache'] def __init__(self, manifest, @@ -1143,6 +1146,17 @@ class Project(object): self._UpdateHooks(quiet=quiet) self._InitRemote() + if _ALTERNATES or self.manifest.is_multimanifest: + # If gitdir/objects is a symlink, migrate it from the old layout. + gitdir_objects = os.path.join(self.gitdir, 'objects') + if platform_utils.islink(gitdir_objects): + platform_utils.remove(gitdir_objects, missing_ok=True) + gitdir_alt = os.path.join(self.gitdir, 'objects/info/alternates') + if not os.path.exists(gitdir_alt): + os.makedirs(os.path.dirname(gitdir_alt), exist_ok=True) + _lwrite(gitdir_alt, os.path.join( + os.path.relpath(self.objdir, gitdir_objects), 'objects') + '\n') + if is_new: alt = os.path.join(self.objdir, 'objects/info/alternates') try: