project: move --reference handling to project-objects

When using --reference, the path is written to objects/info/alternates.
The path is accessed inconsistently -- sometimes through projects/ (via
self.gitdir) and sometimes through project-objects/ (via self.objdir).
This works because projects/.../objects is a symlink to the objects dir
under project-objects/.  Change all accesses to go through self.objdir.
This will allow us to stop symlinking projects/.../objects without the
reference dir logic breaking.  The projects/ path is going to use its
alternates file for its own needs.

Bug: https://crbug.com/gerrit/15553
Change-Id: I6b452ad1aaffec74ecb7ac1bb9baa3a3a52e076c
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/328099
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Jack Neus <jackneus@google.com>
This commit is contained in:
Mike Frysinger 2021-12-20 21:17:43 -05:00
parent a3ac816278
commit 152032cca2

View File

@ -1120,7 +1120,7 @@ class Project(object):
self._InitRemote()
if is_new:
alt = os.path.join(self.gitdir, 'objects/info/alternates')
alt = os.path.join(self.objdir, 'objects/info/alternates')
try:
with open(alt) as fd:
# This works for both absolute and relative alternate directories.
@ -1169,7 +1169,7 @@ class Project(object):
mp = self.manifest.manifestProject
dissociate = mp.config.GetBoolean('repo.dissociate')
if dissociate:
alternates_file = os.path.join(self.gitdir, 'objects/info/alternates')
alternates_file = os.path.join(self.objdir, 'objects/info/alternates')
if os.path.exists(alternates_file):
cmd = ['repack', '-a', '-d']
p = GitCommand(self, cmd, bare=True, capture_stdout=bool(output_redir),
@ -2504,8 +2504,8 @@ class Project(object):
if ref_dir or mirror_git:
if not mirror_git:
mirror_git = os.path.join(ref_dir, self.name + '.git')
repo_git = os.path.join(ref_dir, '.repo', 'projects',
self.relpath + '.git')
repo_git = os.path.join(ref_dir, '.repo', 'project-objects',
self.name + '.git')
worktrees_git = os.path.join(ref_dir, '.repo', 'worktrees',
self.name + '.git')
@ -2523,7 +2523,7 @@ class Project(object):
# The alternate directory is relative to the object database.
ref_dir = os.path.relpath(ref_dir,
os.path.join(self.objdir, 'objects'))
_lwrite(os.path.join(self.gitdir, 'objects/info/alternates'),
_lwrite(os.path.join(self.objdir, 'objects/info/alternates'),
os.path.join(ref_dir, 'objects') + '\n')
m = self.manifest.manifestProject.config