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
+12 -12
View File
@@ -74,7 +74,7 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
return fmt.Errorf("GetRepositoryByOwnerAndName failed: %w", err)
}
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
gitRepo, err := gitrepo.OpenRepository(repo)
if err != nil {
return fmt.Errorf("OpenRepository[%s]: %w", repo.FullName(), err)
}
@@ -120,11 +120,11 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
delTags = append(delTags, tagName)
notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
} else { // is new tag
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
newCommit, err := gitRepo.GetCommit(ctx, opts.NewCommitID)
if err != nil {
// in case there is dirty data, for example, the "github.com/git/git" repository has tags pointing to non-existing commits
if !errors.Is(err, util.ErrNotExist) {
log.Error("Unable to get tag commit: gitRepo.GetCommit(%s) in %s/%s[%d]: %v", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
log.Error("Unable to get tag commit: gitRepo.GetCommit(ctx, %s) in %s/%s[%d]: %v", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
}
} else {
commits := repo_module.NewPushCommits()
@@ -160,9 +160,9 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
newCommit, err := gitRepo.GetCommit(ctx, opts.NewCommitID)
if err != nil {
return fmt.Errorf("gitRepo.GetCommit(%s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
return fmt.Errorf("gitRepo.GetCommit(ctx, %s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
}
// Push new branch.
@@ -197,7 +197,7 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
log.Error("updateIssuesCommit: %v", err)
}
commits.CompareURL = getCompareURL(repo, gitRepo, objectFormat, commits.Commits, opts)
commits.CompareURL = getCompareURL(ctx, repo, gitRepo, objectFormat, commits.Commits, opts)
if len(commits.Commits) > setting.UI.FeedMaxCommitNum {
commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum]
@@ -236,10 +236,10 @@ func pushQueueHandleUpdates(optsList []*repo_module.PushUpdateOptions) error {
return nil
}
func getCompareURL(repo *repo_model.Repository, gitRepo *git.Repository, objectFormat git.ObjectFormat, commits []*repo_module.PushCommit, opts *repo_module.PushUpdateOptions) string {
func getCompareURL(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, objectFormat git.ObjectFormat, commits []*repo_module.PushCommit, opts *repo_module.PushUpdateOptions) string {
oldCommitID := opts.OldCommitID
if oldCommitID == objectFormat.EmptyObjectID().String() && len(commits) > 0 {
oldCommit, err := gitRepo.GetCommit(commits[len(commits)-1].Sha1)
oldCommit, err := gitRepo.GetCommit(ctx, commits[len(commits)-1].Sha1)
if err != nil && !git.IsErrNotExist(err) {
log.Error("unable to GetCommit %s from %-v: %v", oldCommitID, repo, err)
}
@@ -279,7 +279,7 @@ func pushNewBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *gi
}
}
l, err := newCommit.CommitsBeforeLimit(gitRepo, 10)
l, err := newCommit.CommitsBeforeLimit(ctx, gitRepo, 10)
if err != nil {
return nil, fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err)
}
@@ -288,7 +288,7 @@ func pushNewBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *gi
}
func pushUpdateBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pusher *user_model.User, opts *repo_module.PushUpdateOptions, newCommit *git.Commit) ([]*git.Commit, error) {
l, err := newCommit.CommitsBeforeUntil(gitRepo, git.RefNameFromCommit(opts.OldCommitID))
l, err := newCommit.CommitsBeforeUntil(ctx, gitRepo, git.RefNameFromCommit(opts.OldCommitID))
if err != nil {
return nil, fmt.Errorf("newCommit.CommitsBeforeUntil: %w", err)
}
@@ -370,11 +370,11 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
newReleases := make([]*repo_model.Release, 0, len(lowerTags)-len(relMap))
for i, lowerTag := range lowerTags {
tag, err := gitRepo.GetTag(tags[i])
tag, err := gitRepo.GetTag(ctx, tags[i])
if err != nil {
return fmt.Errorf("GetTag: %w", err)
}
commit, err := gitRepo.GetTagCommit(tag.Name)
commit, err := gitRepo.GetTagCommit(ctx, tag.Name)
if err != nil {
return fmt.Errorf("Commit: %w", err)
}