mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-02 17:59:29 +00:00
refactor: remove Ctx field from git.Repository (#38500)
This commit is contained in:
+11
-10
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user