Refactor git command context & pipeline (#36406)

Less and simpler code, fewer bugs
This commit is contained in:
wxiaoguang
2026-01-21 09:35:14 +08:00
committed by GitHub
parent f6db180a80
commit 9ea91e036f
36 changed files with 286 additions and 434 deletions

View File

@@ -9,7 +9,6 @@ import (
"context"
"fmt"
"io"
"os"
"strconv"
"strings"
@@ -60,25 +59,11 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan
close(outputChan)
}()
lsFilesReader, lsFilesWriter, err := os.Pipe()
if err != nil {
log.Error("Unable to open stderr pipe: %v", err)
outputChan <- &lsFileLine{err: fmt.Errorf("unable to open stderr pipe: %w", err)}
return
}
defer func() {
_ = lsFilesWriter.Close()
_ = lsFilesReader.Close()
}()
err = gitcmd.NewCommand("ls-files", "-u", "-z").
var lsFilesReader io.ReadCloser
err := gitcmd.NewCommand("ls-files", "-u", "-z").
WithDir(tmpBasePath).
WithStdout(lsFilesWriter).
WithPipelineFunc(func(_ context.Context, _ context.CancelFunc) error {
_ = lsFilesWriter.Close()
defer func() {
_ = lsFilesReader.Close()
}()
WithStdoutReader(&lsFilesReader).
WithPipelineFunc(func(_ gitcmd.Context) error {
bufferedReader := bufio.NewReader(lsFilesReader)
for {