Skip to content

Commit 3e88af8

Browse files
authored
Make git.OpenRepository accept Context (#19260)
* OpenRepositoryCtx -> OpenRepository * OpenRepository -> openRepositoryWithDefaultContext, only for internal usage
1 parent 889a8c2 commit 3e88af8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+176
-170
lines changed

cmd/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
724724
log.Trace("Processing next %d repos of %d", len(repos), count)
725725
for _, repo := range repos {
726726
log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath())
727-
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
727+
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
728728
if err != nil {
729729
log.Warn("OpenRepository: %v", err)
730730
continue

integrations/api_releases_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
105105
session := loginUser(t, owner.LowerName)
106106
token := getTokenForLoggedInUser(t, session)
107107

108-
gitRepo, err := git.OpenRepository(repo.RepoPath())
108+
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath())
109109
assert.NoError(t, err)
110110
defer gitRepo.Close()
111111

@@ -167,7 +167,7 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
167167
session := loginUser(t, owner.LowerName)
168168
token := getTokenForLoggedInUser(t, session)
169169

170-
gitRepo, err := git.OpenRepository(repo.RepoPath())
170+
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath())
171171
assert.NoError(t, err)
172172
defer gitRepo.Close()
173173

integrations/api_repo_file_create_test.go

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

77
import (
8+
stdCtx "context"
89
"encoding/base64"
910
"fmt"
1011
"net/http"
@@ -167,7 +168,7 @@ func TestAPICreateFile(t *testing.T) {
167168
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
168169
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
169170
resp := session.MakeRequest(t, req, http.StatusCreated)
170-
gitRepo, _ := git.OpenRepository(repo1.RepoPath())
171+
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
171172
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
172173
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath)
173174
var fileResponse api.FileResponse
@@ -286,7 +287,7 @@ func TestAPICreateFile(t *testing.T) {
286287
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
287288
resp = session.MakeRequest(t, req, http.StatusCreated)
288289
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}).(*repo_model.Repository) // public repo
289-
gitRepo, _ := git.OpenRepository(emptyRepo.RepoPath())
290+
gitRepo, _ := git.OpenRepository(stdCtx.Background(), emptyRepo.RepoPath())
290291
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
291292
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath)
292293
DecodeJSON(t, resp, &fileResponse)

integrations/api_repo_file_update_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package integrations
66

77
import (
8+
stdCtx "context"
89
"encoding/base64"
910
"fmt"
1011
"net/http"
@@ -134,7 +135,7 @@ func TestAPIUpdateFile(t *testing.T) {
134135
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
135136
req := NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
136137
resp := session.MakeRequest(t, req, http.StatusOK)
137-
gitRepo, _ := git.OpenRepository(repo1.RepoPath())
138+
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
138139
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
139140
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath)
140141
var fileResponse api.FileResponse

integrations/api_repo_get_contents_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
7575
err := repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, repo1.DefaultBranch, newBranch)
7676
assert.NoError(t, err)
7777
// Get the commit ID of the default branch
78-
gitRepo, err := git.OpenRepository(repo1.RepoPath())
78+
gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath())
7979
assert.NoError(t, err)
8080
defer gitRepo.Close()
8181

integrations/api_repo_get_contents_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
7676
err := repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, repo1.DefaultBranch, newBranch)
7777
assert.NoError(t, err)
7878
// Get the commit ID of the default branch
79-
gitRepo, err := git.OpenRepository(repo1.RepoPath())
79+
gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath())
8080
assert.NoError(t, err)
8181
defer gitRepo.Close()
8282

integrations/api_repo_git_tags_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestAPIGitTags(t *testing.T) {
3131
git.NewCommand(git.DefaultContext, "config", "user.name", user.Name).RunInDir(repo.RepoPath())
3232
git.NewCommand(git.DefaultContext, "config", "user.email", user.Email).RunInDir(repo.RepoPath())
3333

34-
gitRepo, _ := git.OpenRepository(repo.RepoPath())
34+
gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
3535
defer gitRepo.Close()
3636

3737
commit, _ := gitRepo.GetBranchCommit("master")

integrations/git_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
624624
return
625625
}
626626

627-
gitRepo, err := git.OpenRepository(dstPath)
627+
gitRepo, err := git.OpenRepository(git.DefaultContext, dstPath)
628628
if !assert.NoError(t, err) {
629629
return
630630
}

integrations/mirror_pull_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestMirrorPull(t *testing.T) {
5252
mirror, err := repository.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
5353
assert.NoError(t, err)
5454

55-
gitRepo, err := git.OpenRepository(repoPath)
55+
gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
5656
assert.NoError(t, err)
5757
defer gitRepo.Close()
5858

integrations/mirror_push_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ func testMirrorPush(t *testing.T, u *url.URL) {
5454
ok := mirror_service.SyncPushMirror(context.Background(), mirrors[0].ID)
5555
assert.True(t, ok)
5656

57-
srcGitRepo, err := git.OpenRepository(srcRepo.RepoPath())
57+
srcGitRepo, err := git.OpenRepository(git.DefaultContext, srcRepo.RepoPath())
5858
assert.NoError(t, err)
5959
defer srcGitRepo.Close()
6060

6161
srcCommit, err := srcGitRepo.GetBranchCommit("master")
6262
assert.NoError(t, err)
6363

64-
mirrorGitRepo, err := git.OpenRepository(mirrorRepo.RepoPath())
64+
mirrorGitRepo, err := git.OpenRepository(git.DefaultContext, mirrorRepo.RepoPath())
6565
assert.NoError(t, err)
6666
defer mirrorGitRepo.Close()
6767

0 commit comments

Comments
 (0)