From 3e88af898a7b8e2697f7e4c3867c34b802d0b660 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Mar 2022 21:13:41 +0200 Subject: [PATCH] Make git.OpenRepository accept Context (#19260) * OpenRepositoryCtx -> OpenRepository * OpenRepository -> openRepositoryWithDefaultContext, only for internal usage --- cmd/admin.go | 2 +- integrations/api_releases_test.go | 4 ++-- integrations/api_repo_file_create_test.go | 5 +++-- integrations/api_repo_file_update_test.go | 3 ++- .../api_repo_get_contents_list_test.go | 2 +- integrations/api_repo_get_contents_test.go | 2 +- integrations/api_repo_git_tags_test.go | 2 +- integrations/git_test.go | 2 +- integrations/mirror_pull_test.go | 2 +- integrations/mirror_push_test.go | 4 ++-- integrations/pull_merge_test.go | 4 ++-- integrations/pull_update_test.go | 2 +- integrations/repofiles_update_test.go | 8 +++---- models/migrations/v156.go | 2 +- models/migrations/v82.go | 2 +- models/organization/team_repo.go | 1 + models/organization/team_user.go | 1 + models/repo.go | 12 +++++----- models/repo/fork.go | 4 ++-- models/repo/fork_test.go | 5 +++-- modules/context/api.go | 4 ++-- modules/context/repo.go | 6 ++--- modules/convert/pull.go | 8 +++---- modules/doctor/misc.go | 2 +- modules/git/blob_test.go | 4 ++-- modules/git/commit_info_test.go | 6 ++--- modules/git/commit_test.go | 4 ++-- modules/git/diff.go | 2 +- modules/git/notes_test.go | 6 ++--- modules/git/repo_base.go | 2 +- modules/git/repo_base_gogit.go | 10 ++++----- modules/git/repo_base_nogogit.go | 10 ++++----- modules/git/repo_blob_test.go | 6 ++--- modules/git/repo_branch.go | 2 +- modules/git/repo_branch_gogit.go | 2 +- modules/git/repo_branch_test.go | 4 ++-- modules/git/repo_commit_test.go | 10 ++++----- modules/git/repo_compare_test.go | 6 ++--- modules/git/repo_language_stats_test.go | 2 +- modules/git/repo_ref_test.go | 4 ++-- modules/git/repo_stats_test.go | 2 +- modules/git/repo_tag_test.go | 6 ++--- modules/git/repo_test.go | 2 +- modules/git/tree_entry_test.go | 2 +- modules/gitgraph/graph_test.go | 2 +- modules/indexer/stats/db.go | 2 +- modules/markup/html.go | 2 +- modules/repository/generate.go | 2 +- modules/repository/init.go | 2 +- modules/repository/repo.go | 2 +- modules/test/context_tests.go | 4 ++-- routers/api/v1/repo/file.go | 2 +- routers/api/v1/repo/fork.go | 2 +- routers/api/v1/repo/notes.go | 2 +- routers/api/v1/repo/pull.go | 4 ++-- routers/api/v1/repo/repo.go | 2 +- routers/api/v1/repo/wiki.go | 2 +- routers/api/v1/utils/git.go | 2 +- routers/private/internal_repo.go | 2 +- routers/web/repo/branch.go | 2 +- routers/web/repo/commit.go | 2 +- routers/web/repo/compare.go | 6 ++--- routers/web/repo/editor_test.go | 2 +- routers/web/repo/lfs.go | 2 +- routers/web/repo/pull.go | 12 +++++----- routers/web/repo/wiki.go | 2 +- routers/web/repo/wiki_test.go | 2 +- services/asymkey/sign.go | 10 ++++----- services/gitdiff/gitdiff_test.go | 2 +- services/migrations/dump.go | 2 +- services/migrations/gitea_uploader.go | 2 +- services/migrations/gitea_uploader_test.go | 4 ++-- services/mirror/mirror_pull.go | 4 ++-- services/mirror/mirror_push.go | 2 +- services/pull/check.go | 2 +- services/pull/patch.go | 2 +- services/pull/pull.go | 8 +++---- services/pull/review.go | 2 +- services/release/release_test.go | 6 ++--- services/repository/adopt.go | 2 +- services/repository/archiver/archiver.go | 2 +- services/repository/files/file_test.go | 2 +- services/repository/files/temp_repo.go | 4 ++-- services/repository/fork.go | 22 +++++++++---------- services/repository/fork_test.go | 3 ++- services/repository/hooks.go | 4 ++-- services/repository/push.go | 2 +- services/wiki/wiki.go | 4 ++-- services/wiki/wiki_test.go | 10 ++++----- 89 files changed, 176 insertions(+), 170 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index 52081348a8..e4a254c613 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -724,7 +724,7 @@ func runRepoSyncReleases(_ *cli.Context) error { log.Trace("Processing next %d repos of %d", len(repos), count) for _, repo := range repos { log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath()) - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { log.Warn("OpenRepository: %v", err) continue diff --git a/integrations/api_releases_test.go b/integrations/api_releases_test.go index 815b749110..80f53717b6 100644 --- a/integrations/api_releases_test.go +++ b/integrations/api_releases_test.go @@ -105,7 +105,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) { session := loginUser(t, owner.LowerName) token := getTokenForLoggedInUser(t, session) - gitRepo, err := git.OpenRepository(repo.RepoPath()) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath()) assert.NoError(t, err) defer gitRepo.Close() @@ -167,7 +167,7 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) { session := loginUser(t, owner.LowerName) token := getTokenForLoggedInUser(t, session) - gitRepo, err := git.OpenRepository(repo.RepoPath()) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath()) assert.NoError(t, err) defer gitRepo.Close() diff --git a/integrations/api_repo_file_create_test.go b/integrations/api_repo_file_create_test.go index 8bee5d39f4..eb550f1d28 100644 --- a/integrations/api_repo_file_create_test.go +++ b/integrations/api_repo_file_create_test.go @@ -5,6 +5,7 @@ package integrations import ( + stdCtx "context" "encoding/base64" "fmt" "net/http" @@ -167,7 +168,7 @@ func TestAPICreateFile(t *testing.T) { url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2) req := NewRequestWithJSON(t, "POST", url, &createFileOptions) resp := session.MakeRequest(t, req, http.StatusCreated) - gitRepo, _ := git.OpenRepository(repo1.RepoPath()) + gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath()) commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName) expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath) var fileResponse api.FileResponse @@ -286,7 +287,7 @@ func TestAPICreateFile(t *testing.T) { req = NewRequestWithJSON(t, "POST", url, &createFileOptions) resp = session.MakeRequest(t, req, http.StatusCreated) emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}).(*repo_model.Repository) // public repo - gitRepo, _ := git.OpenRepository(emptyRepo.RepoPath()) + gitRepo, _ := git.OpenRepository(stdCtx.Background(), emptyRepo.RepoPath()) commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName) expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath) DecodeJSON(t, resp, &fileResponse) diff --git a/integrations/api_repo_file_update_test.go b/integrations/api_repo_file_update_test.go index 63bee11458..0c9c0763f4 100644 --- a/integrations/api_repo_file_update_test.go +++ b/integrations/api_repo_file_update_test.go @@ -5,6 +5,7 @@ package integrations import ( + stdCtx "context" "encoding/base64" "fmt" "net/http" @@ -134,7 +135,7 @@ func TestAPIUpdateFile(t *testing.T) { url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2) req := NewRequestWithJSON(t, "PUT", url, &updateFileOptions) resp := session.MakeRequest(t, req, http.StatusOK) - gitRepo, _ := git.OpenRepository(repo1.RepoPath()) + gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath()) commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName) expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath) var fileResponse api.FileResponse diff --git a/integrations/api_repo_get_contents_list_test.go b/integrations/api_repo_get_contents_list_test.go index b8822d13ec..42227a9c4b 100644 --- a/integrations/api_repo_get_contents_list_test.go +++ b/integrations/api_repo_get_contents_list_test.go @@ -75,7 +75,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) { err := repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, repo1.DefaultBranch, newBranch) assert.NoError(t, err) // Get the commit ID of the default branch - gitRepo, err := git.OpenRepository(repo1.RepoPath()) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath()) assert.NoError(t, err) defer gitRepo.Close() diff --git a/integrations/api_repo_get_contents_test.go b/integrations/api_repo_get_contents_test.go index bc8471c70d..67f2cb8362 100644 --- a/integrations/api_repo_get_contents_test.go +++ b/integrations/api_repo_get_contents_test.go @@ -76,7 +76,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) { err := repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, repo1.DefaultBranch, newBranch) assert.NoError(t, err) // Get the commit ID of the default branch - gitRepo, err := git.OpenRepository(repo1.RepoPath()) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath()) assert.NoError(t, err) defer gitRepo.Close() diff --git a/integrations/api_repo_git_tags_test.go b/integrations/api_repo_git_tags_test.go index 6aa2f9f642..7884560df8 100644 --- a/integrations/api_repo_git_tags_test.go +++ b/integrations/api_repo_git_tags_test.go @@ -31,7 +31,7 @@ func TestAPIGitTags(t *testing.T) { git.NewCommand(git.DefaultContext, "config", "user.name", user.Name).RunInDir(repo.RepoPath()) git.NewCommand(git.DefaultContext, "config", "user.email", user.Email).RunInDir(repo.RepoPath()) - gitRepo, _ := git.OpenRepository(repo.RepoPath()) + gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) defer gitRepo.Close() commit, _ := gitRepo.GetBranchCommit("master") diff --git a/integrations/git_test.go b/integrations/git_test.go index 675b1879fa..e48d17c9b0 100644 --- a/integrations/git_test.go +++ b/integrations/git_test.go @@ -624,7 +624,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB return } - gitRepo, err := git.OpenRepository(dstPath) + gitRepo, err := git.OpenRepository(git.DefaultContext, dstPath) if !assert.NoError(t, err) { return } diff --git a/integrations/mirror_pull_test.go b/integrations/mirror_pull_test.go index eb798fe2ce..385f0f5a6f 100644 --- a/integrations/mirror_pull_test.go +++ b/integrations/mirror_pull_test.go @@ -52,7 +52,7 @@ func TestMirrorPull(t *testing.T) { mirror, err := repository.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil) assert.NoError(t, err) - gitRepo, err := git.OpenRepository(repoPath) + gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath) assert.NoError(t, err) defer gitRepo.Close() diff --git a/integrations/mirror_push_test.go b/integrations/mirror_push_test.go index c5f45643ec..a73b69e786 100644 --- a/integrations/mirror_push_test.go +++ b/integrations/mirror_push_test.go @@ -54,14 +54,14 @@ func testMirrorPush(t *testing.T, u *url.URL) { ok := mirror_service.SyncPushMirror(context.Background(), mirrors[0].ID) assert.True(t, ok) - srcGitRepo, err := git.OpenRepository(srcRepo.RepoPath()) + srcGitRepo, err := git.OpenRepository(git.DefaultContext, srcRepo.RepoPath()) assert.NoError(t, err) defer srcGitRepo.Close() srcCommit, err := srcGitRepo.GetBranchCommit("master") assert.NoError(t, err) - mirrorGitRepo, err := git.OpenRepository(mirrorRepo.RepoPath()) + mirrorGitRepo, err := git.OpenRepository(git.DefaultContext, mirrorRepo.RepoPath()) assert.NoError(t, err) defer mirrorGitRepo.Close() diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index 2e33d7095f..f865a3371e 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -238,7 +238,7 @@ func TestCantMergeConflict(t *testing.T) { BaseBranch: "base", }).(*models.PullRequest) - gitRepo, err := git.OpenRepository(repo_model.RepoPath(user1.Name, repo1.Name)) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name)) assert.NoError(t, err) err = pull.Merge(git.DefaultContext, pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT") @@ -333,7 +333,7 @@ func TestCantMergeUnrelated(t *testing.T) { session.MakeRequest(t, req, http.StatusCreated) // Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point... - gitRepo, err := git.OpenRepository(path) + gitRepo, err := git.OpenRepository(git.DefaultContext, path) assert.NoError(t, err) pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ HeadRepoID: repo1.ID, diff --git a/integrations/pull_update_test.go b/integrations/pull_update_test.go index dc2803aca0..20b4eaeb4a 100644 --- a/integrations/pull_update_test.go +++ b/integrations/pull_update_test.go @@ -90,7 +90,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *models.Pul assert.NoError(t, err) assert.NotEmpty(t, baseRepo) - headRepo, err := repo_service.ForkRepository(actor, forkOrg, repo_service.ForkRepoOptions{ + headRepo, err := repo_service.ForkRepository(git.DefaultContext, actor, forkOrg, repo_service.ForkRepoOptions{ BaseRepo: baseRepo, Name: "repo-pr-update", Description: "desc", diff --git a/integrations/repofiles_update_test.go b/integrations/repofiles_update_test.go index bb11a048e4..2add99cc86 100644 --- a/integrations/repofiles_update_test.go +++ b/integrations/repofiles_update_test.go @@ -202,7 +202,7 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) { // asserts assert.NoError(t, err) - gitRepo, _ := git.OpenRepository(repo.RepoPath()) + gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) defer gitRepo.Close() commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch) @@ -238,7 +238,7 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) { // asserts assert.NoError(t, err) - gitRepo, _ := git.OpenRepository(repo.RepoPath()) + gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) defer gitRepo.Close() commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch) @@ -273,7 +273,7 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) { // asserts assert.NoError(t, err) - gitRepo, _ := git.OpenRepository(repo.RepoPath()) + gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) defer gitRepo.Close() commit, _ := gitRepo.GetBranchCommit(opts.NewBranch) @@ -323,7 +323,7 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) { // asserts assert.NoError(t, err) - gitRepo, _ := git.OpenRepository(repo.RepoPath()) + gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) defer gitRepo.Close() commitID, _ := gitRepo.GetBranchCommitID(repo.DefaultBranch) diff --git a/models/migrations/v156.go b/models/migrations/v156.go index 77aed3ff57..26f97fe984 100644 --- a/models/migrations/v156.go +++ b/models/migrations/v156.go @@ -109,7 +109,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error { return err } } - gitRepo, err = git.OpenRepositoryCtx(git.DefaultContext, repoPath(repo.OwnerName, repo.Name)) + gitRepo, err = git.OpenRepository(git.DefaultContext, repoPath(repo.OwnerName, repo.Name)) if err != nil { log.Error("Error whilst opening git repo for [%d]%s/%s. Error: %v", repo.ID, repo.OwnerName, repo.Name, err) return err diff --git a/models/migrations/v82.go b/models/migrations/v82.go index 7f9f979d95..8e07e633c9 100644 --- a/models/migrations/v82.go +++ b/models/migrations/v82.go @@ -99,7 +99,7 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error { userCache[repo.OwnerID] = user } - gitRepo, err = git.OpenRepositoryCtx(git.DefaultContext, RepoPath(user.Name, repo.Name)) + gitRepo, err = git.OpenRepository(git.DefaultContext, RepoPath(user.Name, repo.Name)) if err != nil { return err } diff --git a/models/organization/team_repo.go b/models/organization/team_repo.go index e6ac751829..03ca4678a5 100644 --- a/models/organization/team_repo.go +++ b/models/organization/team_repo.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" repo_model "code.gitea.io/gitea/models/repo" + "xorm.io/builder" ) diff --git a/models/organization/team_user.go b/models/organization/team_user.go index e972817f49..80f4d00e3d 100644 --- a/models/organization/team_user.go +++ b/models/organization/team_user.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" + "xorm.io/builder" ) diff --git a/models/repo.go b/models/repo.go index 70539e849b..628a102ee2 100644 --- a/models/repo.go +++ b/models/repo.go @@ -247,8 +247,8 @@ func CanUserForkRepo(user *user_model.User, repo *repo_model.Repository) (bool, } // FindUserOrgForks returns the forked repositories for one user from a repository -func FindUserOrgForks(repoID, userID int64) ([]*repo_model.Repository, error) { - var cond builder.Cond = builder.And( +func FindUserOrgForks(ctx context.Context, repoID, userID int64) ([]*repo_model.Repository, error) { + cond := builder.And( builder.Eq{"fork_id": repoID}, builder.In("owner_id", builder.Select("org_id"). @@ -258,23 +258,23 @@ func FindUserOrgForks(repoID, userID int64) ([]*repo_model.Repository, error) { ) var repos []*repo_model.Repository - return repos, db.GetEngine(db.DefaultContext).Table("repository").Where(cond).Find(&repos) + return repos, db.GetEngine(ctx).Table("repository").Where(cond).Find(&repos) } // GetForksByUserAndOrgs return forked repos of the user and owned orgs -func GetForksByUserAndOrgs(user *user_model.User, repo *repo_model.Repository) ([]*repo_model.Repository, error) { +func GetForksByUserAndOrgs(ctx context.Context, user *user_model.User, repo *repo_model.Repository) ([]*repo_model.Repository, error) { var repoList []*repo_model.Repository if user == nil { return repoList, nil } - forkedRepo, err := repo_model.GetUserFork(repo.ID, user.ID) + forkedRepo, err := repo_model.GetUserFork(ctx, repo.ID, user.ID) if err != nil { return repoList, err } if forkedRepo != nil { repoList = append(repoList, forkedRepo) } - orgForks, err := FindUserOrgForks(repo.ID, user.ID) + orgForks, err := FindUserOrgForks(ctx, repo.ID, user.ID) if err != nil { return nil, err } diff --git a/models/repo/fork.go b/models/repo/fork.go index 570a5b68ab..ae7882a02e 100644 --- a/models/repo/fork.go +++ b/models/repo/fork.go @@ -44,9 +44,9 @@ func HasForkedRepo(ownerID, repoID int64) bool { } // GetUserFork return user forked repository from this repository, if not forked return nil -func GetUserFork(repoID, userID int64) (*Repository, error) { +func GetUserFork(ctx context.Context, repoID, userID int64) (*Repository, error) { var forkedRepo Repository - has, err := db.GetEngine(db.DefaultContext).Where("fork_id = ?", repoID).And("owner_id = ?", userID).Get(&forkedRepo) + has, err := db.GetEngine(ctx).Where("fork_id = ?", repoID).And("owner_id = ?", userID).Get(&forkedRepo) if err != nil { return nil, err } diff --git a/models/repo/fork_test.go b/models/repo/fork_test.go index bf6b90b388..263aec4e3a 100644 --- a/models/repo/fork_test.go +++ b/models/repo/fork_test.go @@ -7,6 +7,7 @@ package repo import ( "testing" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" "github.com/stretchr/testify/assert" @@ -19,14 +20,14 @@ func TestGetUserFork(t *testing.T) { repo, err := GetRepositoryByID(10) assert.NoError(t, err) assert.NotNil(t, repo) - repo, err = GetUserFork(repo.ID, 13) + repo, err = GetUserFork(db.DefaultContext, repo.ID, 13) assert.NoError(t, err) assert.NotNil(t, repo) repo, err = GetRepositoryByID(9) assert.NoError(t, err) assert.NotNil(t, repo) - repo, err = GetUserFork(repo.ID, 13) + repo, err = GetUserFork(db.DefaultContext, repo.ID, 13) assert.NoError(t, err) assert.Nil(t, repo) } diff --git a/modules/context/api.go b/modules/context/api.go index e847ca35fa..ae516503e4 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -331,7 +331,7 @@ func ReferencesGitRepo(allowEmpty bool) func(ctx *APIContext) (cancel context.Ca // For API calls. if ctx.Repo.GitRepo == nil { repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) - gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath) + gitRepo, err := git.OpenRepository(ctx, repoPath) if err != nil { ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err) return @@ -388,7 +388,7 @@ func RepoRefForAPI(next http.Handler) http.Handler { if ctx.Repo.GitRepo == nil { repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) - ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, repoPath) + ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath) if err != nil { ctx.InternalServerError(err) return diff --git a/modules/context/repo.go b/modules/context/repo.go index b4ffb21cce..5a9e38a1d9 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -529,7 +529,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { } ctx.Data["CanSignedUserFork"] = canSignedUserFork - userAndOrgForks, err := models.GetForksByUserAndOrgs(ctx.Doer, ctx.Repo.Repository) + userAndOrgForks, err := models.GetForksByUserAndOrgs(ctx, ctx.Doer, ctx.Repo.Repository) if err != nil { ctx.ServerError("GetForksByUserAndOrgs", err) return @@ -588,7 +588,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { return } - gitRepo, err := git.OpenRepositoryCtx(ctx, repo_model.RepoPath(userName, repoName)) + gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(userName, repoName)) if err != nil { if strings.Contains(err.Error(), "repository does not exist") || strings.Contains(err.Error(), "no such file or directory") { log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err) @@ -846,7 +846,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context if ctx.Repo.GitRepo == nil { repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) - ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, repoPath) + ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath) if err != nil { ctx.ServerError("RepoRef Invalid repo "+repoPath, err) return diff --git a/modules/convert/pull.go b/modules/convert/pull.go index 1551645a51..cea1028e16 100644 --- a/modules/convert/pull.go +++ b/modules/convert/pull.go @@ -85,7 +85,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo }, } - gitRepo, err := git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) if err != nil { log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err) return nil @@ -111,7 +111,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo } if pr.Flow == models.PullRequestFlowAGit { - gitRepo, err := git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) if err != nil { log.Error("OpenRepository[%s]: %v", pr.GetGitRefName(), err) return nil @@ -138,7 +138,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo apiPullRequest.Head.RepoID = pr.HeadRepo.ID apiPullRequest.Head.Repository = ToRepo(pr.HeadRepo, p.AccessMode) - headGitRepo, err := git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath()) + headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) if err != nil { log.Error("OpenRepository[%s]: %v", pr.HeadRepo.RepoPath(), err) return nil @@ -174,7 +174,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo } if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 { - baseGitRepo, err := git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath()) + baseGitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) if err != nil { log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err) return nil diff --git a/modules/doctor/misc.go b/modules/doctor/misc.go index e96890fbab..f1b7773c28 100644 --- a/modules/doctor/misc.go +++ b/modules/doctor/misc.go @@ -88,7 +88,7 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error { numRepos++ - r, err := git.OpenRepositoryCtx(git.DefaultContext, repo.RepoPath()) + r, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { return err } diff --git a/modules/git/blob_test.go b/modules/git/blob_test.go index 34d8054d1e..39f3f11162 100644 --- a/modules/git/blob_test.go +++ b/modules/git/blob_test.go @@ -17,7 +17,7 @@ import ( func TestBlob_Data(t *testing.T) { output := "file2\n" bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - repo, err := OpenRepository(bareRepo1Path) + repo, err := openRepositoryWithDefaultContext(bareRepo1Path) if !assert.NoError(t, err) { t.Fatal() } @@ -39,7 +39,7 @@ func TestBlob_Data(t *testing.T) { func Benchmark_Blob_Data(b *testing.B) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - repo, err := OpenRepository(bareRepo1Path) + repo, err := openRepositoryWithDefaultContext(bareRepo1Path) if err != nil { b.Fatal(err) } diff --git a/modules/git/commit_info_test.go b/modules/git/commit_info_test.go index 42bed75a3d..49845522a9 100644 --- a/modules/git/commit_info_test.go +++ b/modules/git/commit_info_test.go @@ -112,7 +112,7 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) { func TestEntries_GetCommitsInfo(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() @@ -123,7 +123,7 @@ func TestEntries_GetCommitsInfo(t *testing.T) { assert.NoError(t, err) } defer util.RemoveAll(clonedPath) - clonedRepo1, err := OpenRepository(clonedPath) + clonedRepo1, err := openRepositoryWithDefaultContext(clonedPath) if err != nil { assert.NoError(t, err) } @@ -156,7 +156,7 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) { } defer util.RemoveAll(repoPath) - if repo, err = OpenRepository(repoPath); err != nil { + if repo, err = openRepositoryWithDefaultContext(repoPath); err != nil { b.Fatal(err) } defer repo.Close() diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go index 6e9dd34ea7..aac7de5d46 100644 --- a/modules/git/commit_test.go +++ b/modules/git/commit_test.go @@ -64,7 +64,7 @@ gpgsig -----BEGIN PGP SIGNATURE----- empty commit` sha := SHA1{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2} - gitRepo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare")) + gitRepo, err := openRepositoryWithDefaultContext(filepath.Join(testReposDir, "repo1_bare")) assert.NoError(t, err) assert.NotNil(t, gitRepo) @@ -109,7 +109,7 @@ empty commit`, commitFromReader.Signature.Payload) func TestHasPreviousCommit(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - repo, err := OpenRepository(bareRepo1Path) + repo, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) commit, err := repo.GetCommit("8006ff9adbf0cb94da7dad9e537e53817f9fa5c0") diff --git a/modules/git/diff.go b/modules/git/diff.go index 621878f620..e15b2aa410 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -51,7 +51,7 @@ func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io func GetRawDiffForFile(ctx context.Context, repoPath, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error { repo, closer, err := RepositoryFromContextOrOpen(ctx, repoPath) if err != nil { - return fmt.Errorf("OpenRepository: %v", err) + return fmt.Errorf("RepositoryFromContextOrOpen: %v", err) } defer closer.Close() diff --git a/modules/git/notes_test.go b/modules/git/notes_test.go index fec46e5960..34e7178bea 100644 --- a/modules/git/notes_test.go +++ b/modules/git/notes_test.go @@ -14,7 +14,7 @@ import ( func TestGetNotes(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() @@ -27,7 +27,7 @@ func TestGetNotes(t *testing.T) { func TestGetNestedNotes(t *testing.T) { repoPath := filepath.Join(testReposDir, "repo3_notes") - repo, err := OpenRepository(repoPath) + repo, err := openRepositoryWithDefaultContext(repoPath) assert.NoError(t, err) defer repo.Close() @@ -42,7 +42,7 @@ func TestGetNestedNotes(t *testing.T) { func TestGetNonExistentNotes(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() diff --git a/modules/git/repo_base.go b/modules/git/repo_base.go index 8c2f19f6d7..710f0de9f6 100644 --- a/modules/git/repo_base.go +++ b/modules/git/repo_base.go @@ -44,6 +44,6 @@ func RepositoryFromContextOrOpen(ctx context.Context, path string) (*Repository, return gitRepo, nopCloser(nil), nil } - gitRepo, err := OpenRepositoryCtx(ctx, path) + gitRepo, err := OpenRepository(ctx, path) return gitRepo, gitRepo, err } diff --git a/modules/git/repo_base_gogit.go b/modules/git/repo_base_gogit.go index 23009d80f7..059f75fb3c 100644 --- a/modules/git/repo_base_gogit.go +++ b/modules/git/repo_base_gogit.go @@ -35,13 +35,13 @@ type Repository struct { Ctx context.Context } -// OpenRepository opens the repository at the given path. -func OpenRepository(repoPath string) (*Repository, error) { - return OpenRepositoryCtx(DefaultContext, repoPath) +// openRepositoryWithDefaultContext opens the repository at the given path with DefaultContext. +func openRepositoryWithDefaultContext(repoPath string) (*Repository, error) { + return OpenRepository(DefaultContext, repoPath) } -// OpenRepositoryCtx opens the repository at the given path within the context.Context -func OpenRepositoryCtx(ctx context.Context, repoPath string) (*Repository, error) { +// OpenRepository opens the repository at the given path within the context.Context +func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) { repoPath, err := filepath.Abs(repoPath) if err != nil { return nil, err diff --git a/modules/git/repo_base_nogogit.go b/modules/git/repo_base_nogogit.go index ad4a00be1f..c4a0e82c89 100644 --- a/modules/git/repo_base_nogogit.go +++ b/modules/git/repo_base_nogogit.go @@ -36,13 +36,13 @@ type Repository struct { Ctx context.Context } -// OpenRepository opens the repository at the given path. -func OpenRepository(repoPath string) (*Repository, error) { - return OpenRepositoryCtx(DefaultContext, repoPath) +// openRepositoryWithDefaultContext opens the repository at the given path with DefaultContext. +func openRepositoryWithDefaultContext(repoPath string) (*Repository, error) { + return OpenRepository(DefaultContext, repoPath) } -// OpenRepositoryCtx opens the repository at the given path with the provided context. -func OpenRepositoryCtx(ctx context.Context, repoPath string) (*Repository, error) { +// OpenRepository opens the repository at the given path with the provided context. +func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) { repoPath, err := filepath.Abs(repoPath) if err != nil { return nil, err diff --git a/modules/git/repo_blob_test.go b/modules/git/repo_blob_test.go index 132a3fa50c..9f0b865377 100644 --- a/modules/git/repo_blob_test.go +++ b/modules/git/repo_blob_test.go @@ -15,7 +15,7 @@ import ( func TestRepository_GetBlob_Found(t *testing.T) { repoPath := filepath.Join(testReposDir, "repo1_bare") - r, err := OpenRepository(repoPath) + r, err := openRepositoryWithDefaultContext(repoPath) assert.NoError(t, err) defer r.Close() @@ -43,7 +43,7 @@ func TestRepository_GetBlob_Found(t *testing.T) { func TestRepository_GetBlob_NotExist(t *testing.T) { repoPath := filepath.Join(testReposDir, "repo1_bare") - r, err := OpenRepository(repoPath) + r, err := openRepositoryWithDefaultContext(repoPath) assert.NoError(t, err) defer r.Close() @@ -57,7 +57,7 @@ func TestRepository_GetBlob_NotExist(t *testing.T) { func TestRepository_GetBlob_NoId(t *testing.T) { repoPath := filepath.Join(testReposDir, "repo1_bare") - r, err := OpenRepository(repoPath) + r, err := openRepositoryWithDefaultContext(repoPath) assert.NoError(t, err) defer r.Close() diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go index d9a7a47771..e0d47ad7ac 100644 --- a/modules/git/repo_branch.go +++ b/modules/git/repo_branch.go @@ -89,7 +89,7 @@ func (repo *Repository) GetBranch(branch string) (*Branch, error) { // GetBranchesByPath returns a branch by it's path // if limit = 0 it will not limit func GetBranchesByPath(ctx context.Context, path string, skip, limit int) ([]*Branch, int, error) { - gitRepo, err := OpenRepositoryCtx(ctx, path) + gitRepo, err := OpenRepository(ctx, path) if err != nil { return nil, 0, err } diff --git a/modules/git/repo_branch_gogit.go b/modules/git/repo_branch_gogit.go index 59ae0eaa09..bf3eb857b9 100644 --- a/modules/git/repo_branch_gogit.go +++ b/modules/git/repo_branch_gogit.go @@ -88,7 +88,7 @@ func WalkReferences(ctx context.Context, repoPath string, walkfn func(sha1, refn repo := RepositoryFromContext(ctx, repoPath) if repo == nil { var err error - repo, err = OpenRepositoryCtx(ctx, repoPath) + repo, err = OpenRepository(ctx, repoPath) if err != nil { return 0, err } diff --git a/modules/git/repo_branch_test.go b/modules/git/repo_branch_test.go index ac5f5deea9..add04cb4a7 100644 --- a/modules/git/repo_branch_test.go +++ b/modules/git/repo_branch_test.go @@ -13,7 +13,7 @@ import ( func TestRepository_GetBranches(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() @@ -41,7 +41,7 @@ func TestRepository_GetBranches(t *testing.T) { func BenchmarkRepository_GetBranches(b *testing.B) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) if err != nil { b.Fatal(err) } diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go index 232d6a218c..7b3a5101f2 100644 --- a/modules/git/repo_commit_test.go +++ b/modules/git/repo_commit_test.go @@ -13,7 +13,7 @@ import ( func TestRepository_GetCommitBranches(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() @@ -40,7 +40,7 @@ func TestRepository_GetCommitBranches(t *testing.T) { func TestGetTagCommitWithSignature(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() @@ -54,7 +54,7 @@ func TestGetTagCommitWithSignature(t *testing.T) { func TestGetCommitWithBadCommitID(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() @@ -66,7 +66,7 @@ func TestGetCommitWithBadCommitID(t *testing.T) { func TestIsCommitInBranch(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() @@ -81,7 +81,7 @@ func TestIsCommitInBranch(t *testing.T) { func TestRepository_CommitsBetweenIDs(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo4_commitsbetween") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index 82d3257c0f..e163a3090b 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -24,7 +24,7 @@ func TestGetFormatPatch(t *testing.T) { } defer util.RemoveAll(clonedPath) - repo, err := OpenRepository(clonedPath) + repo, err := openRepositoryWithDefaultContext(clonedPath) if err != nil { assert.NoError(t, err) return @@ -52,7 +52,7 @@ func TestGetFormatPatch(t *testing.T) { func TestReadPatch(t *testing.T) { // Ensure we can read the patch files bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - repo, err := OpenRepository(bareRepo1Path) + repo, err := openRepositoryWithDefaultContext(bareRepo1Path) if err != nil { assert.NoError(t, err) return @@ -91,7 +91,7 @@ func TestReadWritePullHead(t *testing.T) { } defer util.RemoveAll(clonedPath) - repo, err := OpenRepository(clonedPath) + repo, err := openRepositoryWithDefaultContext(clonedPath) if err != nil { assert.NoError(t, err) return diff --git a/modules/git/repo_language_stats_test.go b/modules/git/repo_language_stats_test.go index a77266413a..6a4e23f99b 100644 --- a/modules/git/repo_language_stats_test.go +++ b/modules/git/repo_language_stats_test.go @@ -16,7 +16,7 @@ import ( func TestRepository_GetLanguageStats(t *testing.T) { repoPath := filepath.Join(testReposDir, "language_stats_repo") - gitRepo, err := OpenRepository(repoPath) + gitRepo, err := openRepositoryWithDefaultContext(repoPath) if !assert.NoError(t, err) { t.Fatal() } diff --git a/modules/git/repo_ref_test.go b/modules/git/repo_ref_test.go index 303c496c1d..afd38ca251 100644 --- a/modules/git/repo_ref_test.go +++ b/modules/git/repo_ref_test.go @@ -13,7 +13,7 @@ import ( func TestRepository_GetRefs(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() @@ -37,7 +37,7 @@ func TestRepository_GetRefs(t *testing.T) { func TestRepository_GetRefsFiltered(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() diff --git a/modules/git/repo_stats_test.go b/modules/git/repo_stats_test.go index c5dd66182b..494a161305 100644 --- a/modules/git/repo_stats_test.go +++ b/modules/git/repo_stats_test.go @@ -14,7 +14,7 @@ import ( func TestRepository_GetCodeActivityStats(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) assert.NoError(t, err) defer bareRepo1.Close() diff --git a/modules/git/repo_tag_test.go b/modules/git/repo_tag_test.go index 25fb8fcd9b..0e6afabb4f 100644 --- a/modules/git/repo_tag_test.go +++ b/modules/git/repo_tag_test.go @@ -15,7 +15,7 @@ import ( func TestRepository_GetTags(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) if err != nil { assert.NoError(t, err) return @@ -44,7 +44,7 @@ func TestRepository_GetTag(t *testing.T) { } defer util.RemoveAll(clonedPath) - bareRepo1, err := OpenRepository(clonedPath) + bareRepo1, err := openRepositoryWithDefaultContext(clonedPath) if err != nil { assert.NoError(t, err) return @@ -149,7 +149,7 @@ func TestRepository_GetAnnotatedTag(t *testing.T) { } defer util.RemoveAll(clonedPath) - bareRepo1, err := OpenRepository(clonedPath) + bareRepo1, err := openRepositoryWithDefaultContext(clonedPath) if err != nil { assert.NoError(t, err) return diff --git a/modules/git/repo_test.go b/modules/git/repo_test.go index e143c1b39d..8ca170cd1f 100644 --- a/modules/git/repo_test.go +++ b/modules/git/repo_test.go @@ -23,7 +23,7 @@ func TestGetLatestCommitTime(t *testing.T) { func TestRepoIsEmpty(t *testing.T) { emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty") - repo, err := OpenRepository(emptyRepo2Path) + repo, err := openRepositoryWithDefaultContext(emptyRepo2Path) assert.NoError(t, err) defer repo.Close() isEmpty, err := repo.IsEmpty() diff --git a/modules/git/tree_entry_test.go b/modules/git/tree_entry_test.go index 402c345887..9347e10b1b 100644 --- a/modules/git/tree_entry_test.go +++ b/modules/git/tree_entry_test.go @@ -57,7 +57,7 @@ func TestEntriesCustomSort(t *testing.T) { } func TestFollowLink(t *testing.T) { - r, err := OpenRepository("tests/repos/repo1_bare") + r, err := openRepositoryWithDefaultContext("tests/repos/repo1_bare") assert.NoError(t, err) defer r.Close() diff --git a/modules/gitgraph/graph_test.go b/modules/gitgraph/graph_test.go index e7173b521c..ea6553529a 100644 --- a/modules/gitgraph/graph_test.go +++ b/modules/gitgraph/graph_test.go @@ -14,7 +14,7 @@ import ( ) func BenchmarkGetCommitGraph(b *testing.B) { - currentRepo, err := git.OpenRepository(".") + currentRepo, err := git.OpenRepository(git.DefaultContext, ".") if err != nil || currentRepo == nil { b.Error("Could not open repository") } diff --git a/modules/indexer/stats/db.go b/modules/indexer/stats/db.go index 513f2270da..bb3385ab63 100644 --- a/modules/indexer/stats/db.go +++ b/modules/indexer/stats/db.go @@ -35,7 +35,7 @@ func (db *DBIndexer) Index(id int64) error { return err } - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { if err.Error() == "no such file or directory" { return nil diff --git a/modules/markup/html.go b/modules/markup/html.go index af6ae3bf16..6673f52bf4 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -1079,7 +1079,7 @@ func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) { if !inCache { if ctx.GitRepo == nil { var err error - ctx.GitRepo, err = git.OpenRepositoryCtx(ctx.Ctx, ctx.Metas["repoPath"]) + ctx.GitRepo, err = git.OpenRepository(ctx.Ctx, ctx.Metas["repoPath"]) if err != nil { log.Error("unable to open repository: %s Error: %v", ctx.Metas["repoPath"], err) return diff --git a/modules/repository/generate.go b/modules/repository/generate.go index cf219f4c26..8f0b3c16fe 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -219,7 +219,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r repo.DefaultBranch = templateRepo.DefaultBranch } - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { return fmt.Errorf("openRepository: %v", err) } diff --git a/modules/repository/init.go b/modules/repository/init.go index 52d84946a4..3263beadcb 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -430,7 +430,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re if len(opts.DefaultBranch) > 0 { repo.DefaultBranch = opts.DefaultBranch - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { return fmt.Errorf("openRepository: %v", err) } diff --git a/modules/repository/repo.go b/modules/repository/repo.go index 7170bed8be..3ed48134c3 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -126,7 +126,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, return repo, fmt.Errorf("error in MigrateRepositoryGitData(git update-server-info): %v", err) } - gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath) + gitRepo, err := git.OpenRepository(ctx, repoPath) if err != nil { return repo, fmt.Errorf("OpenRepository: %v", err) } diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go index e43f0429e7..2c6ae2f853 100644 --- a/modules/test/context_tests.go +++ b/modules/test/context_tests.go @@ -66,7 +66,7 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) { // LoadRepoCommit loads a repo's commit into a test context. func LoadRepoCommit(t *testing.T, ctx *context.Context) { - gitRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) assert.NoError(t, err) defer gitRepo.Close() branch, err := gitRepo.GetHEADBranch() @@ -88,7 +88,7 @@ func LoadUser(t *testing.T, ctx *context.Context, userID int64) { func LoadGitRepo(t *testing.T, ctx *context.Context) { assert.NoError(t, ctx.Repo.Repository.GetOwner(ctx)) var err error - ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath()) + ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) assert.NoError(t, err) } diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index 6b3f653c95..a4811b370a 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -122,7 +122,7 @@ func GetArchive(ctx *context.APIContext) { repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame")) if ctx.Repo.GitRepo == nil { - gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath) + gitRepo, err := git.OpenRepository(ctx, repoPath) if err != nil { ctx.Error(http.StatusInternalServerError, "OpenRepository", err) return diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index aaff9107cf..10c05e5503 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -136,7 +136,7 @@ func CreateFork(ctx *context.APIContext) { name = *form.Name } - fork, err := repo_service.ForkRepository(ctx.Doer, forker, repo_service.ForkRepoOptions{ + fork, err := repo_service.ForkRepository(ctx, ctx.Doer, forker, repo_service.ForkRepoOptions{ BaseRepo: repo, Name: name, Description: repo.Description, diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go index edcb27b1ec..f85883566f 100644 --- a/routers/api/v1/repo/notes.go +++ b/routers/api/v1/repo/notes.go @@ -55,7 +55,7 @@ func GetNote(ctx *context.APIContext) { } func getNote(ctx *context.APIContext, identifier string) { - gitRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) if err != nil { ctx.Error(http.StatusInternalServerError, "OpenRepository", err) return diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 1618c74fbc..65544b80b3 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -887,7 +887,7 @@ func MergePullRequest(ctx *context.APIContext) { if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil { headRepo = ctx.Repo.GitRepo } else { - headRepo, err = git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath()) + headRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) if err != nil { ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err) return @@ -981,7 +981,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) headRepo = ctx.Repo.Repository headGitRepo = ctx.Repo.GitRepo } else { - headGitRepo, err = git.OpenRepositoryCtx(ctx, repo_model.RepoPath(headUser.Name, headRepo.Name)) + headGitRepo, err = git.OpenRepository(ctx, repo_model.RepoPath(headUser.Name, headRepo.Name)) if err != nil { ctx.Error(http.StatusInternalServerError, "OpenRepository", err) return nil, nil, nil, nil, "", "" diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 2d979235a0..aca1338a27 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -711,7 +711,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err if ctx.Repo.GitRepo == nil && !repo.IsEmpty { var err error - ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath()) + ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) if err != nil { ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err) return err diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 3ea8a31184..a3a5904925 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -458,7 +458,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) // findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error. // The caller is responsible for closing the returned repo again func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) { - wikiRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath()) + wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) if err != nil { if git.IsErrNotExist(err) || err.Error() == "no such file or directory" { diff --git a/routers/api/v1/utils/git.go b/routers/api/v1/utils/git.go index f7a7fe83c9..9f02bc8083 100644 --- a/routers/api/v1/utils/git.go +++ b/routers/api/v1/utils/git.go @@ -36,7 +36,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string { func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) { if ctx.Repo.GitRepo == nil { var err error - ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath()) + ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) if err != nil { return nil, "OpenRepository", err } diff --git a/routers/private/internal_repo.go b/routers/private/internal_repo.go index ade862c613..c50d2a01a7 100644 --- a/routers/private/internal_repo.go +++ b/routers/private/internal_repo.go @@ -43,7 +43,7 @@ func RepoAssignment(ctx *gitea_context.PrivateContext) context.CancelFunc { return nil } - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err) ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 3fc575a198..0d139ec79c 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -290,7 +290,7 @@ func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, p if pr.HasMerged { baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID] if !ok { - baseGitRepo, err = git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath()) + baseGitRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) if err != nil { ctx.ServerError("OpenRepository", err) return nil diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 36cc005cec..2b1b5440d0 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -265,7 +265,7 @@ func Diff(ctx *context.Context) { ) if ctx.Data["PageIsWiki"] != nil { - gitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath()) + gitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) if err != nil { ctx.ServerError("Repo.GitRepo.GetCommit", err) return diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 902da0c3fe..60c6ae0298 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -389,7 +389,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { ci.HeadRepo = ctx.Repo.Repository ci.HeadGitRepo = ctx.Repo.GitRepo } else if has { - ci.HeadGitRepo, err = git.OpenRepositoryCtx(ctx, ci.HeadRepo.RepoPath()) + ci.HeadGitRepo, err = git.OpenRepository(ctx, ci.HeadRepo.RepoPath()) if err != nil { ctx.ServerError("OpenRepository", err) return nil @@ -661,7 +661,7 @@ func PrepareCompareDiff( } func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repository) (branches, tags []string, err error) { - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { return nil, nil, err } @@ -795,7 +795,7 @@ func ExcerptBlob(ctx *context.Context) { gitRepo := ctx.Repo.GitRepo if ctx.FormBool("wiki") { var err error - gitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath()) + gitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) if err != nil { ctx.ServerError("OpenRepository", err) return diff --git a/routers/web/repo/editor_test.go b/routers/web/repo/editor_test.go index ab7532ebb5..2bebb6fd52 100644 --- a/routers/web/repo/editor_test.go +++ b/routers/web/repo/editor_test.go @@ -67,7 +67,7 @@ func TestGetClosestParentWithFiles(t *testing.T) { repo := ctx.Repo.Repository branch := repo.DefaultBranch - gitRepo, _ := git.OpenRepository(repo.RepoPath()) + gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath()) defer gitRepo.Close() commit, _ := gitRepo.GetBranchCommit(branch) expectedTreePath := "" diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go index 395a47a1f6..e0ef864edf 100644 --- a/routers/web/repo/lfs.go +++ b/routers/web/repo/lfs.go @@ -124,7 +124,7 @@ func LFSLocks(ctx *context.Context) { return } - gitRepo, err := git.OpenRepositoryCtx(ctx, tmpBasePath) + gitRepo, err := git.OpenRepository(ctx, tmpBasePath) if err != nil { log.Error("Unable to open temporary repository: %s (%v)", tmpBasePath, err) ctx.ServerError("LFSLocks", fmt.Errorf("failed to open new temporary repository in: %s %v", tmpBasePath, err)) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index af99f1b275..7b24e5dabb 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -227,7 +227,7 @@ func ForkPost(ctx *context.Context) { } } - repo, err := repo_service.ForkRepository(ctx.Doer, ctxUser, repo_service.ForkRepoOptions{ + repo, err := repo_service.ForkRepository(ctx, ctx.Doer, ctxUser, repo_service.ForkRepoOptions{ BaseRepo: forkRepo, Name: form.RepoName, Description: form.Description, @@ -418,7 +418,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare if pull.BaseRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil { baseGitRepo = ctx.Repo.GitRepo } else { - baseGitRepo, err := git.OpenRepositoryCtx(ctx, pull.BaseRepo.RepoPath()) + baseGitRepo, err := git.OpenRepository(ctx, pull.BaseRepo.RepoPath()) if err != nil { ctx.ServerError("OpenRepository", err) return nil @@ -470,7 +470,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare var headBranchSha string // HeadRepo may be missing if pull.HeadRepo != nil { - headGitRepo, err := git.OpenRepositoryCtx(ctx, pull.HeadRepo.RepoPath()) + headGitRepo, err := git.OpenRepository(ctx, pull.HeadRepo.RepoPath()) if err != nil { ctx.ServerError("OpenRepository", err) return nil @@ -1070,7 +1070,7 @@ func MergePullRequest(ctx *context.Context) { if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil { headRepo = ctx.Repo.GitRepo } else { - headRepo, err = git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath()) + headRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) if err != nil { ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err) return @@ -1280,7 +1280,7 @@ func CleanUpPullRequest(ctx *context.Context) { gitBaseRepo = ctx.Repo.GitRepo } else { // If not just open it - gitBaseRepo, err = git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath()) + gitBaseRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) if err != nil { ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err) return @@ -1295,7 +1295,7 @@ func CleanUpPullRequest(ctx *context.Context) { gitRepo = ctx.Repo.GitRepo } else if pr.BaseRepoID != pr.HeadRepoID { // Otherwise just load it up - gitRepo, err = git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath()) + gitRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) if err != nil { ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err) return diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index 7dcfcd87f0..32f596ff37 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -90,7 +90,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) } func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) { - wikiRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath()) + wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath()) if err != nil { ctx.ServerError("OpenRepository", err) return nil, nil, err diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index 41b5c0f8fd..34f466854f 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -26,7 +26,7 @@ const ( ) func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName string) *git.TreeEntry { - wikiRepo, err := git.OpenRepository(repo.WikiPath()) + wikiRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) assert.NoError(t, err) defer wikiRepo.Close() commit, err := wikiRepo.GetBranchCommit("master") diff --git a/services/asymkey/sign.go b/services/asymkey/sign.go index fa0afe0a57..59f96352de 100644 --- a/services/asymkey/sign.go +++ b/services/asymkey/sign.go @@ -195,7 +195,7 @@ Loop: return false, "", nil, &ErrWontSign{twofa} } case parentSigned: - gitRepo, err := git.OpenRepositoryCtx(ctx, repoWikiPath) + gitRepo, err := git.OpenRepository(ctx, repoWikiPath) if err != nil { return false, "", nil, err } @@ -248,7 +248,7 @@ Loop: return false, "", nil, &ErrWontSign{twofa} } case parentSigned: - gitRepo, err := git.OpenRepositoryCtx(ctx, tmpBasePath) + gitRepo, err := git.OpenRepository(ctx, tmpBasePath) if err != nil { return false, "", nil, err } @@ -322,7 +322,7 @@ Loop: } case baseSigned: if gitRepo == nil { - gitRepo, err = git.OpenRepositoryCtx(ctx, tmpBasePath) + gitRepo, err = git.OpenRepository(ctx, tmpBasePath) if err != nil { return false, "", nil, err } @@ -338,7 +338,7 @@ Loop: } case headSigned: if gitRepo == nil { - gitRepo, err = git.OpenRepositoryCtx(ctx, tmpBasePath) + gitRepo, err = git.OpenRepository(ctx, tmpBasePath) if err != nil { return false, "", nil, err } @@ -354,7 +354,7 @@ Loop: } case commitsSigned: if gitRepo == nil { - gitRepo, err = git.OpenRepositoryCtx(ctx, tmpBasePath) + gitRepo, err = git.OpenRepository(ctx, tmpBasePath) if err != nil { return false, "", nil, err } diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index d57a3e2aba..3457785e5d 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -690,7 +690,7 @@ func TestDiffLine_GetCommentSide(t *testing.T) { } func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) { - gitRepo, err := git.OpenRepository("./testdata/academic-module") + gitRepo, err := git.OpenRepository(git.DefaultContext, "./testdata/academic-module") if !assert.NoError(t, err) { return } diff --git a/services/migrations/dump.go b/services/migrations/dump.go index 594b78511a..9b0adc4a68 100644 --- a/services/migrations/dump.go +++ b/services/migrations/dump.go @@ -182,7 +182,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp } } - g.gitRepo, err = git.OpenRepositoryCtx(g.ctx, g.gitPath()) + g.gitRepo, err = git.OpenRepository(g.ctx, g.gitPath()) return err } diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 607dd0a076..82e57e296d 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -136,7 +136,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate if err != nil { return err } - g.gitRepo, err = git.OpenRepositoryCtx(g.ctx, r.RepoPath()) + g.gitRepo, err = git.OpenRepository(g.ctx, r.RepoPath()) return err } diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go index 34107b7f6a..1d4ec13d1c 100644 --- a/services/migrations/gitea_uploader_test.go +++ b/services/migrations/gitea_uploader_test.go @@ -247,7 +247,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) { Author: &signature, Message: "Initial Commit", })) - fromGitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, fromRepo.RepoPath()) + fromGitRepo, err := git.OpenRepository(git.DefaultContext, fromRepo.RepoPath()) assert.NoError(t, err) defer fromGitRepo.Close() baseSHA, err := fromGitRepo.GetBranchCommitID(baseRef) @@ -290,7 +290,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) { Author: &signature, Message: "branch2 commit", })) - forkGitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, forkRepo.RepoPath()) + forkGitRepo, err := git.OpenRepository(git.DefaultContext, forkRepo.RepoPath()) assert.NoError(t, err) defer forkGitRepo.Close() forkHeadSHA, err := forkGitRepo.GetBranchCommitID(forkHeadRef) diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index a8a646a51b..45749aebfd 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -281,7 +281,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo log.Error("SyncMirrors [repo: %-v]: %v", m.Repo, err) } - gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath) + gitRepo, err := git.OpenRepository(ctx, repoPath) if err != nil { log.Error("SyncMirrors [repo: %-v]: failed to OpenRepository: %v", m.Repo, err) return nil, false @@ -438,7 +438,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo) } else { log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results)) - gitRepo, err = git.OpenRepositoryCtx(ctx, m.Repo.RepoPath()) + gitRepo, err = git.OpenRepository(ctx, m.Repo.RepoPath()) if err != nil { log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err) return false diff --git a/services/mirror/mirror_push.go b/services/mirror/mirror_push.go index b619f9ab32..742338ef5f 100644 --- a/services/mirror/mirror_push.go +++ b/services/mirror/mirror_push.go @@ -137,7 +137,7 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error { if setting.LFS.StartServer { log.Trace("SyncMirrors [repo: %-v]: syncing LFS objects...", m.Repo) - gitRepo, err := git.OpenRepositoryCtx(ctx, path) + gitRepo, err := git.OpenRepository(ctx, path) if err != nil { log.Error("OpenRepository: %v", err) return errors.New("Unexpected error") diff --git a/services/pull/check.go b/services/pull/check.go index 3c79abf4b8..f920688f5d 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -121,7 +121,7 @@ func getMergeCommit(ctx context.Context, pr *models.PullRequest) (*git.Commit, e mergeCommit = commitID[:40] } - gitRepo, err := git.OpenRepositoryCtx(ctx, pr.BaseRepo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) if err != nil { return nil, fmt.Errorf("OpenRepository: %v", err) } diff --git a/services/pull/patch.go b/services/pull/patch.go index 398fadde1a..4c0c91d96a 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -69,7 +69,7 @@ func TestPatch(pr *models.PullRequest) error { } }() - gitRepo, err := git.OpenRepositoryCtx(ctx, tmpBasePath) + gitRepo, err := git.OpenRepository(ctx, tmpBasePath) if err != nil { return fmt.Errorf("OpenRepository: %v", err) } diff --git a/services/pull/pull.go b/services/pull/pull.go index 562912cab9..13e4773d8a 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -83,7 +83,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode } // add first push codes comment - baseGitRepo, err := git.OpenRepositoryCtx(prCtx, pr.BaseRepo.RepoPath()) + baseGitRepo, err := git.OpenRepository(prCtx, pr.BaseRepo.RepoPath()) if err != nil { return err } @@ -224,7 +224,7 @@ func checkForInvalidation(ctx context.Context, requests models.PullRequestList, if err != nil { return fmt.Errorf("GetRepositoryByID: %v", err) } - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { return fmt.Errorf("git.OpenRepository: %v", err) } @@ -352,7 +352,7 @@ func checkIfPRContentChanged(ctx context.Context, pr *models.PullRequest, oldCom return false, fmt.Errorf("LoadBaseRepo: %v", err) } - headGitRepo, err := git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath()) + headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) if err != nil { return false, fmt.Errorf("OpenRepository: %v", err) } @@ -752,7 +752,7 @@ func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (ma } gitRepo, ok := gitRepos[issue.RepoID] if !ok { - gitRepo, err = git.OpenRepositoryCtx(ctx, issue.Repo.RepoPath()) + gitRepo, err = git.OpenRepository(ctx, issue.Repo.RepoPath()) if err != nil { log.Error("Cannot open git repository %-v for issue #%d[%d]. Error: %v", issue.Repo, issue.Index, issue.ID, err) continue diff --git a/services/pull/review.go b/services/pull/review.go index 111e959a87..cb21d736cf 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -127,7 +127,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo } gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath()) if err != nil { - return nil, fmt.Errorf("OpenRepository: %v", err) + return nil, fmt.Errorf("RepositoryFromContextOrOpen: %v", err) } defer closer.Close() diff --git a/services/release/release_test.go b/services/release/release_test.go index 413a56116b..ec2282d7db 100644 --- a/services/release/release_test.go +++ b/services/release/release_test.go @@ -31,7 +31,7 @@ func TestRelease_Create(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) repoPath := repo_model.RepoPath(user.Name, repo.Name) - gitRepo, err := git.OpenRepository(repoPath) + gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath) assert.NoError(t, err) defer gitRepo.Close() @@ -135,7 +135,7 @@ func TestRelease_Update(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) repoPath := repo_model.RepoPath(user.Name, repo.Name) - gitRepo, err := git.OpenRepository(repoPath) + gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath) assert.NoError(t, err) defer gitRepo.Close() @@ -277,7 +277,7 @@ func TestRelease_createTag(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) repoPath := repo_model.RepoPath(user.Name, repo.Name) - gitRepo, err := git.OpenRepository(repoPath) + gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath) assert.NoError(t, err) defer gitRepo.Close() diff --git a/services/repository/adopt.go b/services/repository/adopt.go index e9d1f80545..2523ca7350 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -123,7 +123,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r repo.IsEmpty = false // Don't bother looking this repo in the context it won't be there - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { return fmt.Errorf("openRepository: %v", err) } diff --git a/services/repository/archiver/archiver.go b/services/repository/archiver/archiver.go index ad2141ef33..7c2cf237d5 100644 --- a/services/repository/archiver/archiver.go +++ b/services/repository/archiver/archiver.go @@ -178,7 +178,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) { return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err) } - gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { return nil, err } diff --git a/services/repository/files/file_test.go b/services/repository/files/file_test.go index 24e4949832..ee0582dfc2 100644 --- a/services/repository/files/file_test.go +++ b/services/repository/files/file_test.go @@ -109,7 +109,7 @@ func TestGetFileResponseFromCommit(t *testing.T) { repo := ctx.Repo.Repository branch := repo.DefaultBranch treePath := "README.md" - gitRepo, _ := git.OpenRepositoryCtx(ctx, repo.RepoPath()) + gitRepo, _ := git.OpenRepository(ctx, repo.RepoPath()) defer gitRepo.Close() commit, _ := gitRepo.GetBranchCommit(branch) expectedFileResponse := getExpectedFileResponse() diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go index c789ad4445..66c8f09364 100644 --- a/services/repository/files/temp_repo.go +++ b/services/repository/files/temp_repo.go @@ -69,7 +69,7 @@ func (t *TemporaryUploadRepository) Clone(branch string) error { return fmt.Errorf("Clone: %v %s", err, stderr) } } - gitRepo, err := git.OpenRepositoryCtx(t.ctx, t.basePath) + gitRepo, err := git.OpenRepository(t.ctx, t.basePath) if err != nil { return err } @@ -82,7 +82,7 @@ func (t *TemporaryUploadRepository) Init() error { if err := git.InitRepository(t.ctx, t.basePath, false); err != nil { return err } - gitRepo, err := git.OpenRepositoryCtx(t.ctx, t.basePath) + gitRepo, err := git.OpenRepository(t.ctx, t.basePath) if err != nil { return err } diff --git a/services/repository/fork.go b/services/repository/fork.go index ec8fb1a09e..1a5d358408 100644 --- a/services/repository/fork.go +++ b/services/repository/fork.go @@ -30,8 +30,8 @@ type ForkRepoOptions struct { } // ForkRepository forks a repository -func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo_model.Repository, err error) { - forkedRepo, err := repo_model.GetUserFork(opts.BaseRepo.ID, owner.ID) +func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts ForkRepoOptions) (*repo_model.Repository, error) { + forkedRepo, err := repo_model.GetUserFork(ctx, opts.BaseRepo.ID, owner.ID) if err != nil { return nil, err } @@ -91,24 +91,24 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo panic(panicErr) }() - err = db.WithTx(func(ctx context.Context) error { - if err = models.CreateRepository(ctx, doer, owner, repo, false); err != nil { + err = db.WithTx(func(txCtx context.Context) error { + if err = models.CreateRepository(txCtx, doer, owner, repo, false); err != nil { return err } - if err = models.IncrementRepoForkNum(ctx, opts.BaseRepo.ID); err != nil { + if err = models.IncrementRepoForkNum(txCtx, opts.BaseRepo.ID); err != nil { return err } // copy lfs files failure should not be ignored - if err = models.CopyLFS(ctx, repo, opts.BaseRepo); err != nil { + if err = models.CopyLFS(txCtx, repo, opts.BaseRepo); err != nil { return err } needsRollback = true repoPath := repo_model.RepoPath(owner.Name, repo.Name) - if stdout, err := git.NewCommand(ctx, + if stdout, err := git.NewCommand(txCtx, "clone", "--bare", oldRepoPath, repoPath). SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())). RunInDirTimeout(10*time.Minute, ""); err != nil { @@ -116,11 +116,11 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo return fmt.Errorf("git clone: %v", err) } - if err := models.CheckDaemonExportOK(ctx, repo); err != nil { + if err := models.CheckDaemonExportOK(txCtx, repo); err != nil { return fmt.Errorf("checkDaemonExportOK: %v", err) } - if stdout, err := git.NewCommand(ctx, "update-server-info"). + if stdout, err := git.NewCommand(txCtx, "update-server-info"). SetDescription(fmt.Sprintf("ForkRepository(git update-server-info): %s", repo.FullName())). RunInDir(repoPath); err != nil { log.Error("Fork Repository (git update-server-info) failed for %v:\nStdout: %s\nError: %v", repo, stdout, err) @@ -139,14 +139,14 @@ func ForkRepository(doer, owner *user_model.User, opts ForkRepoOptions) (_ *repo } // even if below operations failed, it could be ignored. And they will be retried - if err := models.UpdateRepoSize(db.DefaultContext, repo); err != nil { + if err := models.UpdateRepoSize(ctx, repo); err != nil { log.Error("Failed to update size for repository: %v", err) } if err := repo_model.CopyLanguageStat(opts.BaseRepo, repo); err != nil { log.Error("Copy language stat from oldRepo failed: %v", err) } - gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.RepoPath()) + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { log.Error("Open created git repository failed: %v", err) } else { diff --git a/services/repository/fork_test.go b/services/repository/fork_test.go index 5d392e224f..965887b5d1 100644 --- a/services/repository/fork_test.go +++ b/services/repository/fork_test.go @@ -11,6 +11,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/git" "github.com/stretchr/testify/assert" ) @@ -22,7 +23,7 @@ func TestForkRepository(t *testing.T) { user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13}).(*user_model.User) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10}).(*repo_model.Repository) - fork, err := ForkRepository(user, user, ForkRepoOptions{ + fork, err := ForkRepository(git.DefaultContext, user, user, ForkRepoOptions{ BaseRepo: repo, Name: "test", Description: "test", diff --git a/services/repository/hooks.go b/services/repository/hooks.go index 40303d5937..67931ffcb6 100644 --- a/services/repository/hooks.go +++ b/services/repository/hooks.go @@ -54,13 +54,13 @@ func SyncRepositoryHooks(ctx context.Context) error { // GenerateGitHooks generates git hooks from a template repository func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error { - generateGitRepo, err := git.OpenRepositoryCtx(ctx, generateRepo.RepoPath()) + generateGitRepo, err := git.OpenRepository(ctx, generateRepo.RepoPath()) if err != nil { return err } defer generateGitRepo.Close() - templateGitRepo, err := git.OpenRepositoryCtx(ctx, templateRepo.RepoPath()) + templateGitRepo, err := git.OpenRepository(ctx, templateRepo.RepoPath()) if err != nil { return err } diff --git a/services/repository/push.go b/services/repository/push.go index 8fbd5f5186..4eb52c18c2 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -89,7 +89,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { repoPath := repo.RepoPath() - gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath) + gitRepo, err := git.OpenRepository(ctx, repoPath) if err != nil { return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err) } diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go index 919753726f..9e14b0cefb 100644 --- a/services/wiki/wiki.go +++ b/services/wiki/wiki.go @@ -156,7 +156,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err) } - gitRepo, err := git.OpenRepositoryCtx(ctx, basePath) + gitRepo, err := git.OpenRepository(ctx, basePath) if err != nil { log.Error("Unable to open temporary repository: %s (%v)", basePath, err) return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err) @@ -305,7 +305,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err) } - gitRepo, err := git.OpenRepositoryCtx(ctx, basePath) + gitRepo, err := git.OpenRepository(ctx, basePath) if err != nil { log.Error("Unable to open temporary repository: %s (%v)", basePath, err) return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err) diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go index 928d08c828..17ec657cac 100644 --- a/services/wiki/wiki_test.go +++ b/services/wiki/wiki_test.go @@ -138,7 +138,7 @@ func TestRepository_AddWikiPage(t *testing.T) { t.Parallel() assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, wikiName, wikiContent, commitMsg)) // Now need to show that the page has been added: - gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.WikiPath()) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) assert.NoError(t, err) defer gitRepo.Close() masterTree, err := gitRepo.GetTree("master") @@ -183,7 +183,7 @@ func TestRepository_EditWikiPage(t *testing.T) { assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", newWikiName, newWikiContent, commitMsg)) // Now need to show that the page has been added: - gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.WikiPath()) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) assert.NoError(t, err) masterTree, err := gitRepo.GetTree("master") assert.NoError(t, err) @@ -207,7 +207,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) { assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home")) // Now need to show that the page has been added: - gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.WikiPath()) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) assert.NoError(t, err) defer gitRepo.Close() masterTree, err := gitRepo.GetTree("master") @@ -220,7 +220,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) { func TestPrepareWikiFileName(t *testing.T) { unittest.PrepareTestEnv(t) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) - gitRepo, err := git.OpenRepositoryCtx(git.DefaultContext, repo.WikiPath()) + gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath()) defer gitRepo.Close() assert.NoError(t, err) @@ -283,7 +283,7 @@ func TestPrepareWikiFileName_FirstPage(t *testing.T) { err = git.InitRepository(git.DefaultContext, tmpDir, true) assert.NoError(t, err) - gitRepo, err := git.OpenRepository(tmpDir) + gitRepo, err := git.OpenRepository(git.DefaultContext, tmpDir) defer gitRepo.Close() assert.NoError(t, err)