mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-22 09:01:25 +00:00
by the way, remove some unnecessary "models" imports from model migration package, fix migration test model init bug (modelmigration/migrationtest/tests.go)
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"gitea.dev/modules/git/gitcmd"
|
|
"gitea.dev/modules/setting"
|
|
)
|
|
|
|
// catFileBatchCommand implements the CatFileBatch interface using the "cat-file --batch-command" command
|
|
// for git version >= 2.36
|
|
// ref: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---batch-command
|
|
type catFileBatchCommand struct {
|
|
ctx context.Context
|
|
repo RepositoryFacade
|
|
batch *catFileBatchCommunicator
|
|
}
|
|
|
|
var _ CatFileBatch = (*catFileBatchCommand)(nil)
|
|
|
|
func newCatFileBatchCommand(ctx context.Context, repo RepositoryFacade) *catFileBatchCommand {
|
|
return &catFileBatchCommand{ctx: ctx, repo: repo}
|
|
}
|
|
|
|
func (b *catFileBatchCommand) getBatch() *catFileBatchCommunicator {
|
|
if b.batch != nil {
|
|
return b.batch
|
|
}
|
|
b.batch = newCatFileBatch(b.ctx, b.repo, gitcmd.NewCommand("cat-file", "--batch-command"))
|
|
return b.batch
|
|
}
|
|
|
|
func (b *catFileBatchCommand) Context() context.Context {
|
|
return b.ctx
|
|
}
|
|
|
|
func (b *catFileBatchCommand) QueryContent(obj string) (*CatFileObject, BufferedReader, error) {
|
|
if strings.Contains(obj, "\n") {
|
|
setting.PanicInDevOrTesting("invalid object name with newline: %q", obj)
|
|
}
|
|
_, err := b.getBatch().reqWriter.Write([]byte("contents " + obj + "\n"))
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
info, err := catFileBatchParseInfoLine(b.getBatch().respReader)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return info, b.getBatch().respReader, nil
|
|
}
|
|
|
|
func (b *catFileBatchCommand) QueryInfo(obj string) (*CatFileObject, error) {
|
|
if strings.Contains(obj, "\n") {
|
|
setting.PanicInDevOrTesting("invalid object name with newline: %q", obj)
|
|
}
|
|
_, err := b.getBatch().reqWriter.Write([]byte("info " + obj + "\n"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return catFileBatchParseInfoLine(b.getBatch().respReader)
|
|
}
|
|
|
|
func (b *catFileBatchCommand) Close() {
|
|
if b.batch != nil {
|
|
b.batch.Close()
|
|
b.batch = nil
|
|
}
|
|
}
|