Skip to content

Commit 4d6e172

Browse files
authored
chore: still keep ctx in git.Repository struct for cat-file batch command (#38684)
Unfortunately, we can't completely remove the ctx from git.Repository, because the CatFileBatch still heavily depends on a parent context. If we remove the Repository ctx, the CatFileBatch will become a mess and create a lot of unnecessary git processes. http://localhost:3000/-/admin/monitor/perftrace * Before: open a repo home, dozens of git processes (duplicate cat-file) * After: only a few (no duplicate cat-file)
1 parent 5672b1c commit 4d6e172

121 files changed

Lines changed: 259 additions & 254 deletions

File tree

Some content is hidden

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

cmd/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func runRepoSyncReleases(ctx context.Context, _ *cli.Command) error {
128128
log.Trace("Processing next %d repos of %d", len(repos), count)
129129
for _, repo := range repos {
130130
log.Trace("Synchronizing repo %s", repo.FullName())
131-
gitRepo, err := git.OpenRepository(repo)
131+
gitRepo, err := git.OpenRepository(ctx, repo)
132132
if err != nil {
133133
log.Warn("OpenRepository: %v", err)
134134
continue

modelmigration/v1_14/v156.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func FixPublisherIDforTagReleases(ctx context.Context, x base.EngineMigration) e
9797
return err
9898
}
9999
}
100-
gitRepo, err = git.OpenRepository(base.LocalCodeGitRepo(repo.OwnerName, repo.Name))
100+
gitRepo, err = git.OpenRepository(ctx, base.LocalCodeGitRepo(repo.OwnerName, repo.Name))
101101
if err != nil {
102102
log.Error("Error whilst opening git repo for [%d]%s/%s. Error: %v", repo.ID, repo.OwnerName, repo.Name, err)
103103
return err

modelmigration/v1_9/v82.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func FixReleaseSha1OnReleaseTable(ctx context.Context, x base.EngineMigration) e
8585
userCache[repo.OwnerID] = user
8686
}
8787

88-
gitRepo, err = git.OpenRepository(base.LocalCodeGitRepo(user.Name, repo.Name))
88+
gitRepo, err = git.OpenRepository(ctx, base.LocalCodeGitRepo(user.Name, repo.Name))
8989
if err != nil {
9090
return err
9191
}

models/git/commit_status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func TestFindRepoRecentCommitStatusContexts(t *testing.T) {
186186

187187
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
188188
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
189-
gitRepo, err := git.OpenRepository(repo2)
189+
gitRepo, err := git.OpenRepository(t.Context(), repo2)
190190
assert.NoError(t, err)
191191
defer gitRepo.Close()
192192

modules/git/attribute/batch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func Test_BatchChecker(t *testing.T) {
119119
setting.AppDataPath = t.TempDir()
120120
repoPath := "../tests/repos/language_stats_repo"
121121
ctx := t.Context()
122-
gitRepo, err := git.OpenRepositoryLocal(repoPath)
122+
gitRepo, err := git.OpenRepositoryLocal(ctx, repoPath)
123123
require.NoError(t, err)
124124
defer gitRepo.Close()
125125

@@ -144,7 +144,7 @@ func Test_BatchChecker(t *testing.T) {
144144
})
145145
assert.NoError(t, err)
146146

147-
tempRepo, err := git.OpenRepositoryLocal(dir)
147+
tempRepo, err := git.OpenRepositoryLocal(ctx, dir)
148148
assert.NoError(t, err)
149149
defer tempRepo.Close()
150150

modules/git/attribute/checker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func Test_Checker(t *testing.T) {
1919
setting.AppDataPath = t.TempDir()
2020
repoPath := "../tests/repos/language_stats_repo"
21-
gitRepo, err := git.OpenRepositoryLocal(repoPath)
21+
gitRepo, err := git.OpenRepositoryLocal(t.Context(), repoPath)
2222
require.NoError(t, err)
2323
defer gitRepo.Close()
2424

@@ -44,7 +44,7 @@ func Test_Checker(t *testing.T) {
4444
})
4545
assert.NoError(t, err)
4646

47-
tempRepo, err := git.OpenRepositoryLocal(dir)
47+
tempRepo, err := git.OpenRepositoryLocal(t.Context(), dir)
4848
assert.NoError(t, err)
4949
defer tempRepo.Close()
5050

modules/git/blame_sha256_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestReadingBlameOutputSha256(t *testing.T) {
2424

2525
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
2626
storage := mockRepository("repo5_pulls_sha256")
27-
repo, err := OpenRepository(storage)
27+
repo, err := OpenRepository(ctx, storage)
2828
assert.NoError(t, err)
2929
defer repo.Close()
3030

@@ -70,7 +70,7 @@ func TestReadingBlameOutputSha256(t *testing.T) {
7070

7171
t.Run("With .git-blame-ignore-revs", func(t *testing.T) {
7272
storage := mockRepository("repo6_blame_sha256")
73-
repo, err := OpenRepository(storage)
73+
repo, err := OpenRepository(ctx, storage)
7474
assert.NoError(t, err)
7575
defer repo.Close()
7676

modules/git/blame_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestReadingBlameOutput(t *testing.T) {
1919

2020
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
2121
storage := mockRepository("repo5_pulls")
22-
repo, err := OpenRepository(storage)
22+
repo, err := OpenRepository(ctx, storage)
2323
assert.NoError(t, err)
2424
defer repo.Close()
2525
commit, err := repo.GetCommit(t.Context(), "f32b0a9dfd09a60f616f29158f772cedd89942d2")
@@ -64,7 +64,7 @@ func TestReadingBlameOutput(t *testing.T) {
6464

6565
t.Run("With .git-blame-ignore-revs", func(t *testing.T) {
6666
storage := mockRepository("repo6_blame")
67-
repo, err := OpenRepository(storage)
67+
repo, err := OpenRepository(ctx, storage)
6868
assert.NoError(t, err)
6969
defer repo.Close()
7070

modules/git/blob_nogogit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Blob struct {
2525
// DataAsync gets a ReadCloser for the contents of a blob without reading it all.
2626
// Calling the Close function on the result will discard all unread output.
2727
func (b *Blob) DataAsync(ctx context.Context) (_ io.ReadCloser, retErr error) {
28-
batch, cancel, err := b.repo.CatFileBatch(ctx)
28+
batch, cancel, err := b.repo.CatFileBatch()
2929
if err != nil {
3030
return nil, err
3131
}
@@ -56,7 +56,7 @@ func (b *Blob) Size(ctx context.Context) int64 {
5656
return b.size
5757
}
5858

59-
batch, cancel, err := b.repo.CatFileBatch(ctx)
59+
batch, cancel, err := b.repo.CatFileBatch()
6060
if err != nil {
6161
log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.LogString(), err)
6262
return 0

modules/git/blob_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func TestBlob_Data(t *testing.T) {
1717
output := "file2\n"
1818
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
19-
repo, err := OpenRepositoryLocal(bareRepo1Path)
19+
repo, err := OpenRepositoryLocal(t.Context(), bareRepo1Path)
2020
require.NoError(t, err)
2121
defer repo.Close()
2222

@@ -36,7 +36,7 @@ func TestBlob_Data(t *testing.T) {
3636

3737
func Benchmark_Blob_Data(b *testing.B) {
3838
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
39-
repo, err := OpenRepositoryLocal(bareRepo1Path)
39+
repo, err := OpenRepositoryLocal(b.Context(), bareRepo1Path)
4040
if err != nil {
4141
b.Fatal(err)
4242
}

0 commit comments

Comments
 (0)