project: init hooks in objdir only

objdir is the .repo/project-objects/ dir based on the remote path.
gitdir is the .repo/projects/ dir based on the local source checkout
path.  When we setup the gitdir, we symlink "hooks" to the one in the
objdir.  But when we go to initialize the hooks, we do it via gitdir.
There is a 1-to-many mapping from project-objects to projects, so
initializing via gitdir can be repetitive.  Collapse the hook init
logic to the objdir init path.

Change-Id: I828fca60ce6e125d6706c709cdb2797faa40aa50
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/323815
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2021-11-15 12:39:00 -05:00
parent fdeb20f43f
commit 333c0a499b

View File

@ -2466,6 +2466,8 @@ class Project(object):
os.makedirs(self.objdir)
self.bare_objdir.init()
self._UpdateHooks(quiet=quiet)
if self.use_git_worktrees:
# Enable per-worktree config file support if possible. This is more a
# nice-to-have feature for users rather than a hard requirement.
@ -2526,8 +2528,6 @@ class Project(object):
_lwrite(os.path.join(self.gitdir, 'objects/info/alternates'),
os.path.join(ref_dir, 'objects') + '\n')
self._UpdateHooks(quiet=quiet)
m = self.manifest.manifestProject.config
for key in ['user.name', 'user.email']:
if m.Has(key, include_defaults=False):
@ -2543,11 +2543,11 @@ class Project(object):
raise
def _UpdateHooks(self, quiet=False):
if os.path.exists(self.gitdir):
if os.path.exists(self.objdir):
self._InitHooks(quiet=quiet)
def _InitHooks(self, quiet=False):
hooks = platform_utils.realpath(self._gitdir_path('hooks'))
hooks = platform_utils.realpath(os.path.join(self.objdir, 'hooks'))
if not os.path.exists(hooks):
os.makedirs(hooks)
for stock_hook in _ProjectHooks():
@ -2831,9 +2831,6 @@ class Project(object):
'for other options.')
return 'filesystem must support symlinks'
def _gitdir_path(self, path):
return platform_utils.realpath(os.path.join(self.gitdir, path))
def _revlist(self, *args, **kw):
a = []
a.extend(args)