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/git | |
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/git')
-rw-r--r-- | modules/git/blob_test.go | 4 | ||||
-rw-r--r-- | modules/git/commit_info_test.go | 6 | ||||
-rw-r--r-- | modules/git/commit_test.go | 4 | ||||
-rw-r--r-- | modules/git/diff.go | 2 | ||||
-rw-r--r-- | modules/git/notes_test.go | 6 | ||||
-rw-r--r-- | modules/git/repo_base.go | 2 | ||||
-rw-r--r-- | modules/git/repo_base_gogit.go | 10 | ||||
-rw-r--r-- | modules/git/repo_base_nogogit.go | 10 | ||||
-rw-r--r-- | modules/git/repo_blob_test.go | 6 | ||||
-rw-r--r-- | modules/git/repo_branch.go | 2 | ||||
-rw-r--r-- | modules/git/repo_branch_gogit.go | 2 | ||||
-rw-r--r-- | modules/git/repo_branch_test.go | 4 | ||||
-rw-r--r-- | modules/git/repo_commit_test.go | 10 | ||||
-rw-r--r-- | modules/git/repo_compare_test.go | 6 | ||||
-rw-r--r-- | modules/git/repo_language_stats_test.go | 2 | ||||
-rw-r--r-- | modules/git/repo_ref_test.go | 4 | ||||
-rw-r--r-- | modules/git/repo_stats_test.go | 2 | ||||
-rw-r--r-- | modules/git/repo_tag_test.go | 6 | ||||
-rw-r--r-- | modules/git/repo_test.go | 2 | ||||
-rw-r--r-- | modules/git/tree_entry_test.go | 2 |
20 files changed, 46 insertions, 46 deletions
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() |