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-20 18:03:28 +00:00
committed by GitHub
parent 9dc04289aa
commit a4526d5a82
28 changed files with 146 additions and 107 deletions
+4 -4
View File
@@ -38,7 +38,7 @@ func ListGitHooks(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
hooks, err := ctx.Repo.GitRepo.Hooks()
hooks, err := git.ListHooks(ctx.Repo.GitRepo)
if err != nil {
ctx.APIErrorInternal(err)
return
@@ -81,7 +81,7 @@ func GetGitHook(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
hookID := ctx.PathParam("id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
hook, err := git.GetHook(ctx.Repo.GitRepo, hookID)
if err != nil {
if errors.Is(err, git.ErrNotValidHook) {
ctx.APIErrorNotFound()
@@ -128,7 +128,7 @@ func EditGitHook(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.EditGitHookOption)
hookID := ctx.PathParam("id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
hook, err := git.GetHook(ctx.Repo.GitRepo, hookID)
if err != nil {
if errors.Is(err, git.ErrNotValidHook) {
ctx.APIErrorNotFound()
@@ -177,7 +177,7 @@ func DeleteGitHook(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
hookID := ctx.PathParam("id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
hook, err := git.GetHook(ctx.Repo.GitRepo, hookID)
if err != nil {
if errors.Is(err, git.ErrNotValidHook) {
ctx.APIErrorNotFound()
+1 -1
View File
@@ -39,7 +39,7 @@ func verifyCommits(ctx context.Context, oldCommitID, newCommitID string, repo *g
}).
Run(ctx)
if err != nil && !isErrUnverifiedCommit(err) {
log.Error("Unable to check commits from %s to %s in %s: %v", oldCommitID, newCommitID, repo.Path, err)
log.Error("Unable to check commits from %s to %s in %s: %v", oldCommitID, newCommitID, repo.LogString(), err)
}
return err
}
+3 -3
View File
@@ -16,7 +16,7 @@ func GitHooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
ctx.Data["PageIsSettingsGitHooks"] = true
hooks, err := ctx.Repo.GitRepo.Hooks()
hooks, err := git.ListHooks(ctx.Repo.GitRepo)
if err != nil {
ctx.ServerError("Hooks", err)
return
@@ -32,7 +32,7 @@ func GitHooksEdit(ctx *context.Context) {
ctx.Data["PageIsSettingsGitHooks"] = true
name := ctx.PathParam("name")
hook, err := ctx.Repo.GitRepo.GetHook(name)
hook, err := git.GetHook(ctx.Repo.GitRepo, name)
if err != nil {
if err == git.ErrNotValidHook {
ctx.NotFound(err)
@@ -49,7 +49,7 @@ func GitHooksEdit(ctx *context.Context) {
// GitHooksEditPost response for editing a git hook of a repository
func GitHooksEditPost(ctx *context.Context) {
name := ctx.PathParam("name")
hook, err := ctx.Repo.GitRepo.GetHook(name)
hook, err := git.GetHook(ctx.Repo.GitRepo, name)
if err != nil {
if err == git.ErrNotValidHook {
ctx.NotFound(err)