refactor: remove Ctx field from git.Repository (#38500)

This commit is contained in:
wxiaoguang
2026-07-17 18:44:31 +08:00
committed by GitHub
parent 2c8e99bbf7
commit 5b078f72aa
235 changed files with 1234 additions and 1258 deletions
@@ -22,7 +22,7 @@ import (
)
// GetLanguageStats calculates language stats for git repository at specified commit
func GetLanguageStats(_ context.Context, repo *git_module.Repository, commitID string) (map[string]int64, error) {
func GetLanguageStats(ctx context.Context, repo *git_module.Repository, commitID string) (map[string]int64, error) {
r, err := git.PlainOpen(repo.Path)
if err != nil {
return nil, err
@@ -43,7 +43,7 @@ func GetLanguageStats(_ context.Context, repo *git_module.Repository, commitID s
return nil, err
}
checker, err := attribute.NewBatchChecker(repo, commitID, attribute.LinguistAttributes)
checker, err := attribute.NewBatchChecker(ctx, repo, commitID, attribute.LinguistAttributes)
if err != nil {
return nil, err
}
@@ -58,7 +58,7 @@ func GetLanguageStats(ctx context.Context, repo *git.Repository, commitID string
return nil, err
}
checker, err := attribute.NewBatchChecker(repo, commitID, attribute.LinguistAttributes)
checker, err := attribute.NewBatchChecker(ctx, repo, commitID, attribute.LinguistAttributes)
if err != nil {
return nil, err
}
@@ -78,8 +78,6 @@ func GetLanguageStats(ctx context.Context, repo *git.Repository, commitID string
for _, f := range entries {
select {
case <-repo.Ctx.Done():
return sizes, repo.Ctx.Err()
case <-ctx.Done():
return sizes, ctx.Err()
default:
@@ -18,7 +18,7 @@ import (
func TestRepository_GetLanguageStats(t *testing.T) {
setting.AppDataPath = t.TempDir()
repoPath := "../tests/repos/language_stats_repo"
gitRepo, err := git.OpenRepository(t.Context(), repoPath)
gitRepo, err := git.OpenRepository(repoPath)
require.NoError(t, err)
defer gitRepo.Close()