feat: vendor gitea 1.16.2

This commit is contained in:
2026-06-02 08:36:01 +00:00
parent 247cd60f69
commit 54798b4615
2145 changed files with 162965 additions and 126447 deletions
+10 -22
View File
@@ -5,8 +5,6 @@
package git
import (
"bytes"
"io"
"strings"
"code.gitea.io/gitea/modules/git/gitcmd"
@@ -33,18 +31,12 @@ func (o ObjectType) Bytes() []byte {
return []byte(o)
}
type EmptyReader struct{}
func (EmptyReader) Read(p []byte) (int, error) {
return 0, io.EOF
}
func (repo *Repository) GetObjectFormat() (ObjectFormat, error) {
if repo != nil && repo.objectFormat != nil {
return repo.objectFormat, nil
}
str, err := repo.hashObject(EmptyReader{}, false)
str, err := repo.hashObjectBytes(nil, false)
if err != nil {
return nil, err
}
@@ -58,32 +50,28 @@ func (repo *Repository) GetObjectFormat() (ObjectFormat, error) {
return repo.objectFormat, nil
}
// HashObject takes a reader and returns hash for that reader
func (repo *Repository) HashObject(reader io.Reader) (ObjectID, error) {
idStr, err := repo.hashObject(reader, true)
// HashObjectBytes returns hash for the content
func (repo *Repository) HashObjectBytes(buf []byte) (ObjectID, error) {
idStr, err := repo.hashObjectBytes(buf, true)
if err != nil {
return nil, err
}
return NewIDFromString(idStr)
}
func (repo *Repository) hashObject(reader io.Reader, save bool) (string, error) {
func (repo *Repository) hashObjectBytes(buf []byte, save bool) (string, error) {
var cmd *gitcmd.Command
if save {
cmd = gitcmd.NewCommand("hash-object", "-w", "--stdin")
} else {
cmd = gitcmd.NewCommand("hash-object", "--stdin")
}
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
err := cmd.Run(repo.Ctx, &gitcmd.RunOpts{
Dir: repo.Path,
Stdin: reader,
Stdout: stdout,
Stderr: stderr,
})
stdout, _, err := cmd.
WithDir(repo.Path).
WithStdinBytes(buf).
RunStdString(repo.Ctx)
if err != nil {
return "", err
}
return strings.TrimSpace(stdout.String()), nil
return strings.TrimSpace(stdout), nil
}