Split parsing from reader (#774)

This commit is contained in:
Bill Rich 2022-09-02 11:02:38 -07:00 committed by GitHub
parent aba56523b6
commit 65a7855713
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"io"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -68,10 +69,6 @@ func RepoPath(ctx context.Context, source string, head string) (chan Commit, err
return commitChan, err return commitChan, err
} }
outReader := bufio.NewReader(stdOut)
var currentCommit *Commit
var currentDiff *Diff
go func() { go func() {
scanner := bufio.NewScanner(stdErr) scanner := bufio.NewScanner(stdErr)
for scanner.Scan() { for scanner.Scan() {
@ -80,6 +77,20 @@ func RepoPath(ctx context.Context, source string, head string) (chan Commit, err
}() }()
go func() { go func() {
FromReader(ctx, stdOut, commitChan)
if err := cmd.Wait(); err != nil {
log.WithError(err).Debugf("Error waiting for git command to complete.")
}
}()
return commitChan, nil
}
func FromReader(ctx context.Context, stdOut io.Reader, commitChan chan Commit) {
outReader := bufio.NewReader(stdOut)
var currentCommit *Commit
var currentDiff *Diff
defer common.Recover(ctx) defer common.Recover(ctx)
for { for {
line, err := outReader.ReadBytes([]byte("\n")[0]) line, err := outReader.ReadBytes([]byte("\n")[0])
@ -164,12 +175,7 @@ func RepoPath(ctx context.Context, source string, head string) (chan Commit, err
if currentCommit != nil { if currentCommit != nil {
commitChan <- *currentCommit commitChan <- *currentCommit
} }
if err := cmd.Wait(); err != nil {
log.WithError(err).Debugf("Error waiting for git command to complete.")
}
close(commitChan) close(commitChan)
}()
return commitChan, nil
} }
// Date: Tue Aug 10 15:20:40 2021 +0100 // Date: Tue Aug 10 15:20:40 2021 +0100