forked from forgejo/forgejo
Make git.OpenRepository accept Context (#19260)
* OpenRepositoryCtx -> OpenRepository * OpenRepository -> openRepositoryWithDefaultContext, only for internal usage
This commit is contained in:
parent
889a8c268c
commit
3e88af898a
89 changed files with 176 additions and 170 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue