Skip to content

Commit

Permalink
Use middleware to open gitRepo (go-gitea#19559)
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 authored and AbdulrhmnGhanem committed Aug 23, 2022
1 parent bc7f7f2 commit cb7af7e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ func Routes() *web.Route {
m.Group("/{ref}", func() {
m.Get("/status", repo.GetCombinedCommitStatusByRef)
m.Get("/statuses", repo.GetCommitStatusesByRef)
})
}, context.ReferencesGitRepo())
}, reqRepoReader(unit.TypeCode))
m.Group("/git", func() {
m.Group("/commits", func() {
Expand Down
8 changes: 2 additions & 6 deletions routers/api/v1/utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package utils

import (
"fmt"
"net/http"

"code.gitea.io/gitea/modules/context"
Expand Down Expand Up @@ -35,12 +36,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
// GetGitRefs return git references based on filter
func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) {
if ctx.Repo.GitRepo == nil {
var err error
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
if err != nil {
return nil, "OpenRepository", err
}
defer ctx.Repo.GitRepo.Close()
return nil, "", fmt.Errorf("no open git repo found in context")
}
if len(filter) > 0 {
filter = "refs/" + filter
Expand Down

0 comments on commit cb7af7e

Please sign in to comment.