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
+11 -10
View File
@@ -5,6 +5,7 @@
package git
import (
"context"
"strings"
"gitea.dev/modules/git/gitcmd"
@@ -31,12 +32,12 @@ func (o ObjectType) Bytes() []byte {
return []byte(o)
}
func (repo *Repository) GetObjectFormat() (ObjectFormat, error) {
if repo != nil && repo.objectFormat != nil {
return repo.objectFormat, nil
func (repo *Repository) GetObjectFormat(ctx context.Context) (ObjectFormat, error) {
if repo.objectFormatCache != nil {
return repo.objectFormatCache, nil
}
str, err := repo.hashObjectBytes(nil, false)
str, err := repo.hashObjectBytes(ctx, nil, false)
if err != nil {
return nil, err
}
@@ -45,21 +46,21 @@ func (repo *Repository) GetObjectFormat() (ObjectFormat, error) {
return nil, err
}
repo.objectFormat = hash.Type()
repo.objectFormatCache = hash.Type()
return repo.objectFormat, nil
return repo.objectFormatCache, nil
}
// HashObjectBytes returns hash for the content
func (repo *Repository) HashObjectBytes(buf []byte) (ObjectID, error) {
idStr, err := repo.hashObjectBytes(buf, true)
func (repo *Repository) HashObjectBytes(ctx context.Context, buf []byte) (ObjectID, error) {
idStr, err := repo.hashObjectBytes(ctx, buf, true)
if err != nil {
return nil, err
}
return NewIDFromString(idStr)
}
func (repo *Repository) hashObjectBytes(buf []byte, save bool) (string, error) {
func (repo *Repository) hashObjectBytes(ctx context.Context, buf []byte, save bool) (string, error) {
var cmd *gitcmd.Command
if save {
cmd = gitcmd.NewCommand("hash-object", "-w", "--stdin")
@@ -69,7 +70,7 @@ func (repo *Repository) hashObjectBytes(buf []byte, save bool) (string, error) {
stdout, _, err := cmd.
WithDir(repo.Path).
WithStdinBytes(buf).
RunStdString(repo.Ctx)
RunStdString(ctx)
if err != nil {
return "", err
}