Skip to content

Commit a7276d9

Browse files
committed
more propagation
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 1d4cbbd commit a7276d9

File tree

17 files changed

+52
-48
lines changed

17 files changed

+52
-48
lines changed

modules/context/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func ReferencesGitRepo(allowEmpty bool) func(http.Handler) http.Handler {
328328
// For API calls.
329329
if ctx.Repo.GitRepo == nil {
330330
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
331-
gitRepo, err := git.OpenRepository(repoPath)
331+
gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
332332
if err != nil {
333333
ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err)
334334
return
@@ -386,7 +386,7 @@ func RepoRefForAPI(next http.Handler) http.Handler {
386386

387387
if ctx.Repo.GitRepo == nil {
388388
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
389-
ctx.Repo.GitRepo, err = git.OpenRepository(repoPath)
389+
ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, repoPath)
390390
if err != nil {
391391
ctx.InternalServerError(err)
392392
return

routers/api/v1/repo/blob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func GetBlob(ctx *context.APIContext) {
4545
ctx.Error(http.StatusBadRequest, "", "sha not provided")
4646
return
4747
}
48-
if blob, err := files_service.GetBlobBySHA(ctx.Repo.Repository, sha); err != nil {
48+
if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, sha); err != nil {
4949
ctx.Error(http.StatusBadRequest, "", err)
5050
} else {
5151
ctx.JSON(http.StatusOK, blob)

routers/api/v1/repo/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func GetContents(ctx *context.APIContext) {
554554
treePath := ctx.Params("*")
555555
ref := ctx.FormTrim("ref")
556556

557-
if fileList, err := files_service.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil {
557+
if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil {
558558
if git.IsErrNotExist(err) {
559559
ctx.NotFound("GetContentsOrList", err)
560560
return

routers/api/v1/repo/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewCommitStatus(ctx *context.APIContext) {
6262
Description: form.Description,
6363
Context: form.Context,
6464
}
65-
if err := files_service.CreateCommitStatus(ctx.Repo.Repository, ctx.User, sha, status); err != nil {
65+
if err := files_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.User, sha, status); err != nil {
6666
ctx.Error(http.StatusInternalServerError, "CreateCommitStatus", err)
6767
return
6868
}

routers/api/v1/repo/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func GetTree(ctx *context.APIContext) {
6060
ctx.Error(http.StatusBadRequest, "", "sha not provided")
6161
return
6262
}
63-
if tree, err := files_service.GetTreeBySHA(ctx.Repo.Repository, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
63+
if tree, err := files_service.GetTreeBySHA(ctx, ctx.Repo.Repository, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
6464
ctx.Error(http.StatusBadRequest, "", err.Error())
6565
} else {
6666
ctx.JSON(http.StatusOK, tree)

routers/api/v1/repo/wiki.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
456456
// findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error.
457457
// The caller is responsible for closing the returned repo again
458458
func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) {
459-
wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
459+
wikiRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath())
460460
if err != nil {
461461

462462
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {

services/migrations/gitea_uploader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
132132
if err != nil {
133133
return err
134134
}
135-
g.gitRepo, err = git.OpenRepository(r.RepoPath())
135+
g.gitRepo, err = git.OpenRepositoryCtx(g.ctx, r.RepoPath())
136136
return err
137137
}
138138

services/repository/adopt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
120120
}
121121

122122
repo.IsEmpty = false
123-
gitRepo, err := git.OpenRepository(repo.RepoPath())
123+
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
124124
if err != nil {
125125
return fmt.Errorf("openRepository: %v", err)
126126
}

services/repository/files/commit.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package files
66

77
import (
8+
"context"
89
"fmt"
910

1011
"code.gitea.io/gitea/models"
@@ -16,11 +17,11 @@ import (
1617
// CreateCommitStatus creates a new CommitStatus given a bunch of parameters
1718
// NOTE: All text-values will be trimmed from whitespaces.
1819
// Requires: Repo, Creator, SHA
19-
func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error {
20+
func CreateCommitStatus(ctx context.Context, repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error {
2021
repoPath := repo.RepoPath()
2122

2223
// confirm that commit is exist
23-
gitRepo, err := git.OpenRepository(repoPath)
24+
gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
2425
if err != nil {
2526
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
2627
}

services/repository/files/content.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package files
66

77
import (
8+
"context"
89
"fmt"
910
"net/url"
1011
"path"
@@ -38,7 +39,7 @@ func (ct *ContentType) String() string {
3839

3940
// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree
4041
// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag
41-
func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) {
42+
func GetContentsOrList(ctx context.Context, repo *models.Repository, treePath, ref string) (interface{}, error) {
4243
if repo.IsEmpty {
4344
return make([]interface{}, 0), nil
4445
}
@@ -56,7 +57,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
5657
}
5758
treePath = cleanTreePath
5859

59-
gitRepo, err := git.OpenRepository(repo.RepoPath())
60+
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
6061
if err != nil {
6162
return nil, err
6263
}
@@ -74,7 +75,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
7475
}
7576

7677
if entry.Type() != "tree" {
77-
return GetContents(repo, treePath, origRef, false)
78+
return GetContents(ctx, repo, treePath, origRef, false)
7879
}
7980

8081
// We are in a directory, so we return a list of FileContentResponse objects
@@ -90,7 +91,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
9091
}
9192
for _, e := range entries {
9293
subTreePath := path.Join(treePath, e.Name())
93-
fileContentResponse, err := GetContents(repo, subTreePath, origRef, true)
94+
fileContentResponse, err := GetContents(ctx, repo, subTreePath, origRef, true)
9495
if err != nil {
9596
return nil, err
9697
}
@@ -100,7 +101,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
100101
}
101102

102103
// GetContents gets the meta data on a file's contents. Ref can be a branch, commit or tag
103-
func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*api.ContentsResponse, error) {
104+
func GetContents(ctx context.Context, repo *models.Repository, treePath, ref string, forList bool) (*api.ContentsResponse, error) {
104105
if ref == "" {
105106
ref = repo.DefaultBranch
106107
}
@@ -115,7 +116,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
115116
}
116117
treePath = cleanTreePath
117118

118-
gitRepo, err := git.OpenRepository(repo.RepoPath())
119+
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
119120
if err != nil {
120121
return nil, err
121122
}
@@ -162,7 +163,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
162163
// Now populate the rest of the ContentsResponse based on entry type
163164
if entry.IsRegular() || entry.IsExecutable() {
164165
contentsResponse.Type = string(ContentTypeRegular)
165-
if blobResponse, err := GetBlobBySHA(repo, entry.ID.String()); err != nil {
166+
if blobResponse, err := GetBlobBySHA(ctx, repo, entry.ID.String()); err != nil {
166167
return nil, err
167168
} else if !forList {
168169
// We don't show the content if we are getting a list of FileContentResponses
@@ -218,8 +219,8 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
218219
}
219220

220221
// GetBlobBySHA get the GitBlobResponse of a repository using a sha hash.
221-
func GetBlobBySHA(repo *models.Repository, sha string) (*api.GitBlobResponse, error) {
222-
gitRepo, err := git.OpenRepository(repo.RepoPath())
222+
func GetBlobBySHA(ctx context.Context, repo *models.Repository, sha string) (*api.GitBlobResponse, error) {
223+
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
223224
if err != nil {
224225
return nil, err
225226
}

0 commit comments

Comments
 (0)