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)
This commit is contained in:
wxiaoguang
2026-07-29 01:04:22 +08:00
committed by GitHub
parent 5672b1c4cf
commit 4d6e172a0d
121 changed files with 259 additions and 254 deletions
+13 -13
View File
@@ -477,7 +477,7 @@ jobs:
assert.NotEmpty(t, addWorkflowToBaseResp)
// Get the commit ID of the default branch
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranchExisting(t.Context(), repo.ID, repo.DefaultBranch)
@@ -787,8 +787,8 @@ func TestPullRequestReviewCommitStatusEvent(t *testing.T) {
assert.NotEmpty(t, repo)
// add user4 as collaborator so they can review
ctx := NewAPITestContext(t, repo.OwnerName, repo.Name, auth_model.AccessTokenScopeWriteRepository)
t.Run("AddUser4AsCollaboratorWithWriteAccess", doAPIAddCollaborator(ctx, "user4", perm.AccessModeWrite))
apiTestCtx := NewAPITestContext(t, repo.OwnerName, repo.Name, auth_model.AccessTokenScopeWriteRepository)
t.Run("AddUser4AsCollaboratorWithWriteAccess", doAPIAddCollaborator(apiTestCtx, "user4", perm.AccessModeWrite))
// add workflow file that triggers on pull_request_review
addWorkflow, err := files_service.ChangeRepoFiles(t.Context(), repo, user2, &files_service.ChangeRepoFilesOptions{
@@ -829,7 +829,7 @@ jobs:
// create a branch and a PR
testBranch := "test-review-branch"
testCreateBranch(t, ctx.Session, repo.OwnerName, repo.Name, "branch/main", testBranch, http.StatusSeeOther)
testCreateBranch(t, apiTestCtx.Session, repo.OwnerName, repo.Name, "branch/main", testBranch, http.StatusSeeOther)
// add a file on the test branch so the PR has changes
addFileResp, err := files_service.ChangeRepoFiles(t.Context(), repo, user2, &files_service.ChangeRepoFilesOptions{
@@ -881,7 +881,7 @@ jobs:
assert.NoError(t, err)
// submit an approval review as user4
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -961,7 +961,7 @@ jobs:
assert.NotEmpty(t, addWorkflowToBaseResp)
// Get the commit ID of the default branch
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranchExisting(t.Context(), repo.ID, repo.DefaultBranch)
@@ -1132,7 +1132,7 @@ jobs:
assert.NotEmpty(t, addWorkflowToBaseResp)
// Get the commit ID of the default branch
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranchExisting(t.Context(), repo.ID, repo.DefaultBranch)
@@ -1223,7 +1223,7 @@ jobs:
assert.NotEmpty(t, addWorkflowToBaseResp)
// Get the commit ID of the default branch
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranchExisting(t.Context(), repo.ID, repo.DefaultBranch)
@@ -1309,7 +1309,7 @@ jobs:
assert.NotEmpty(t, addWorkflowToBaseResp)
// Get the commit ID of the default branch
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranchExisting(t.Context(), repo.ID, repo.DefaultBranch)
@@ -1439,7 +1439,7 @@ jobs:
assert.NotEmpty(t, addWorkflowToBaseResp)
// Get the commit ID of the dispatch branch
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
commit, err := gitRepo.GetBranchCommit(t.Context(), "dispatch")
@@ -1637,7 +1637,7 @@ jobs:
assert.Equal(t, workflows.Workflows[0].State, workflow.State)
// Get the commit ID of the default branch
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranchExisting(t.Context(), repo.ID, repo.DefaultBranch)
@@ -1806,7 +1806,7 @@ jobs:
assert.NoError(t, err)
assert.NotEmpty(t, addWorkflowToBaseResp)
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -1884,7 +1884,7 @@ jobs:
assert.NoError(t, err)
assert.NotEmpty(t, addWorkflowToBaseResp)
gitRepo, err := git.OpenRepository(repo)
gitRepo, err := git.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()