refactor: remove Path field from git.Repository (#38552)

The "path" details should be hidden to other packages

By the way, fix a resource leaking in gogit's CommitNodeIndex
(the file was not closed in CacheCommit)
This commit is contained in:
wxiaoguang
2026-07-21 02:03:28 +08:00
committed by GitHub
parent 9dc04289aa
commit a4526d5a82
28 changed files with 146 additions and 107 deletions
+6 -4
View File
@@ -11,6 +11,7 @@ import (
"slices"
"strings"
"gitea.dev/modules/git/gitcmd"
"gitea.dev/modules/util"
)
@@ -39,7 +40,8 @@ type Hook struct {
}
// GetHook returns a Git hook by given name and repository.
func GetHook(repoPath, name string) (*Hook, error) {
func GetHook(repo RepositoryFacade, name string) (*Hook, error) {
repoPath := gitcmd.RepoLocalPath(repo)
if !IsValidHookName(name) {
return nil, ErrNotValidHook
}
@@ -97,8 +99,8 @@ func (h *Hook) Update() error {
}
// ListHooks returns a list of Git hooks of given repository.
func ListHooks(repoPath string) (_ []*Hook, err error) {
exist, err := util.IsDir(filepath.Join(repoPath, "hooks"))
func ListHooks(repo RepositoryFacade) (_ []*Hook, err error) {
exist, err := util.IsDir(filepath.Join(gitcmd.RepoLocalPath(repo), "hooks"))
if err != nil {
return nil, err
} else if !exist {
@@ -107,7 +109,7 @@ func ListHooks(repoPath string) (_ []*Hook, err error) {
hooks := make([]*Hook, len(hookNames))
for i, name := range hookNames {
hooks[i], err = GetHook(repoPath, name)
hooks[i], err = GetHook(repo, name)
if err != nil {
return nil, err
}