Skip to content

Commit f0b6480

Browse files
committed
Fix linkt error
1 parent 7c3c288 commit f0b6480

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

modules/git/batch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func newBatchCatFileWithCheck(ctx context.Context, repoPath string) (*batchCatFi
4949
}
5050

5151
var batch batchCatFile
52-
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repoPath, "--batch")
52+
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repoPath, true)
5353

5454
var check batchCatFile
5555
check.Writer, check.Reader, check.cancel = catFileBatchCheck(ctx, repoPath)
@@ -102,7 +102,7 @@ func newBatchCommandCatFile(ctx context.Context, repoPath string) (*batchCommand
102102
}
103103

104104
var batch batchCatFile
105-
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repoPath, "--batch-command")
105+
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repoPath, false)
106106

107107
return &batchCommandCatFile{
108108
batch: &batch,

modules/git/batch_reader.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"strconv"
1313
"strings"
1414

15-
"code.gitea.io/gitea/modules/git/internal"
1615
"code.gitea.io/gitea/modules/log"
16+
"code.gitea.io/gitea/modules/util"
1717

1818
"github.com/djherbis/buffer"
1919
"github.com/djherbis/nio/v3"
@@ -89,7 +89,8 @@ func catFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError,
8989

9090
// catFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function
9191
// batchArg is the argument to pass to cat-file --batch, e.g. "--batch" or "--batch-command"
92-
func catFileBatch(ctx context.Context, repoPath, batchArg string) (WriteCloserError, *bufio.Reader, func()) {
92+
// If batchOrBatchCommnd is false, it will use "--batch-command" instead of "--batch".
93+
func catFileBatch(ctx context.Context, repoPath string, batchOrBatchCommnd bool) (WriteCloserError, *bufio.Reader, func()) {
9394
// We often want to feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary.
9495
// so let's create a batch stdin and stdout
9596
batchStdinReader, batchStdinWriter := io.Pipe()
@@ -109,10 +110,15 @@ func catFileBatch(ctx context.Context, repoPath, batchArg string) (WriteCloserEr
109110
cancel()
110111
}()
111112

113+
const (
114+
batchCmdArg = "--batch"
115+
batchCommandArg = "--batch-command"
116+
)
117+
112118
go func() {
113119
stderr := strings.Builder{}
114120
err := NewCommand("cat-file").
115-
AddArguments(internal.CmdArg(batchArg)).
121+
AddArguments(toTrustCmdArg(util.Iif(batchOrBatchCommnd, batchCmdArg, batchCommandArg))).
116122
Run(ctx, &RunOpts{
117123
Dir: repoPath,
118124
Stdin: batchStdinReader,

modules/git/command.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ func (c *Command) AddDashesAndList(list ...string) *Command {
196196
return c
197197
}
198198

199+
// toTrustCmdArg converts a string (trusted as argument) to CmdArg
200+
// In most cases, it shouldn't be used. Use AddXxx function instead
201+
func toTrustCmdArg(arg string) internal.CmdArg {
202+
return internal.CmdArg(arg)
203+
}
204+
199205
// ToTrustedCmdArgs converts a list of strings (trusted as argument) to TrustedCmdArgs
200206
// In most cases, it shouldn't be used. Use NewCommand().AddXxx() function instead
201207
func ToTrustedCmdArgs(args []string) TrustedCmdArgs {

0 commit comments

Comments
 (0)