diff options
author | 6543 <6543@obermui.de> | 2022-03-29 21:13:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-30 03:13:41 +0800 |
commit | 3e88af898a7b8e2697f7e4c3867c34b802d0b660 (patch) | |
tree | e8304867b9fd8d78ef0a3da7221d84fb29592c21 /modules | |
parent | 889a8c268ca6a54ff5be19e61b29b10feb4a12e8 (diff) | |
download | gitea-3e88af898a7b8e2697f7e4c3867c34b802d0b660.tar.gz gitea-3e88af898a7b8e2697f7e4c3867c34b802d0b660.zip |
Make git.OpenRepository accept Context (#19260)
* OpenRepositoryCtx -> OpenRepository
* OpenRepository -> openRepositoryWithDefaultContext, only for internal usage
Diffstat (limited to 'modules')
31 files changed, 64 insertions, 64 deletions
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) } |