mirror of
https://github.com/go-gitea/gitea.git
synced 2025-10-13 12:16:09 +00:00
Move some functions to gitrepo package (#35543)
Refactor Git command functions to use WithXXX methods instead of exposing RunOpts. This change simplifies reuse across gitrepo and improves consistency, encapsulation, and maintainability of command options. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -73,48 +73,47 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan
|
||||
|
||||
stderr := &strings.Builder{}
|
||||
err = gitcmd.NewCommand("ls-files", "-u", "-z").
|
||||
Run(ctx, &gitcmd.RunOpts{
|
||||
Dir: tmpBasePath,
|
||||
Stdout: lsFilesWriter,
|
||||
Stderr: stderr,
|
||||
PipelineFunc: func(_ context.Context, _ context.CancelFunc) error {
|
||||
_ = lsFilesWriter.Close()
|
||||
defer func() {
|
||||
_ = lsFilesReader.Close()
|
||||
}()
|
||||
bufferedReader := bufio.NewReader(lsFilesReader)
|
||||
WithDir(tmpBasePath).
|
||||
WithStdout(lsFilesWriter).
|
||||
WithStderr(stderr).
|
||||
WithPipelineFunc(func(_ context.Context, _ context.CancelFunc) error {
|
||||
_ = lsFilesWriter.Close()
|
||||
defer func() {
|
||||
_ = lsFilesReader.Close()
|
||||
}()
|
||||
bufferedReader := bufio.NewReader(lsFilesReader)
|
||||
|
||||
for {
|
||||
line, err := bufferedReader.ReadString('\000')
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
for {
|
||||
line, err := bufferedReader.ReadString('\000')
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
toemit := &lsFileLine{}
|
||||
|
||||
split := strings.SplitN(line, " ", 3)
|
||||
if len(split) < 3 {
|
||||
return fmt.Errorf("malformed line: %s", line)
|
||||
}
|
||||
toemit.mode = split[0]
|
||||
toemit.sha = split[1]
|
||||
|
||||
if len(split[2]) < 4 {
|
||||
return fmt.Errorf("malformed line: %s", line)
|
||||
}
|
||||
|
||||
toemit.stage, err = strconv.Atoi(split[2][0:1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("malformed line: %s", line)
|
||||
}
|
||||
|
||||
toemit.path = split[2][2 : len(split[2])-1]
|
||||
outputChan <- toemit
|
||||
return err
|
||||
}
|
||||
},
|
||||
})
|
||||
toemit := &lsFileLine{}
|
||||
|
||||
split := strings.SplitN(line, " ", 3)
|
||||
if len(split) < 3 {
|
||||
return fmt.Errorf("malformed line: %s", line)
|
||||
}
|
||||
toemit.mode = split[0]
|
||||
toemit.sha = split[1]
|
||||
|
||||
if len(split[2]) < 4 {
|
||||
return fmt.Errorf("malformed line: %s", line)
|
||||
}
|
||||
|
||||
toemit.stage, err = strconv.Atoi(split[2][0:1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("malformed line: %s", line)
|
||||
}
|
||||
|
||||
toemit.path = split[2][2 : len(split[2])-1]
|
||||
outputChan <- toemit
|
||||
}
|
||||
}).
|
||||
Run(ctx)
|
||||
if err != nil {
|
||||
outputChan <- &lsFileLine{err: fmt.Errorf("git ls-files -u -z: %w", gitcmd.ConcatenateError(err, stderr.String()))}
|
||||
}
|
||||
|
Reference in New Issue
Block a user