mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 15:14:38 +00:00
Split parsing from reader (#774)
This commit is contained in:
parent
aba56523b6
commit
65a7855713
1 changed files with 95 additions and 89 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -68,10 +69,6 @@ func RepoPath(ctx context.Context, source string, head string) (chan Commit, err
|
|||
return commitChan, err
|
||||
}
|
||||
|
||||
outReader := bufio.NewReader(stdOut)
|
||||
var currentCommit *Commit
|
||||
var currentDiff *Diff
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(stdErr)
|
||||
for scanner.Scan() {
|
||||
|
@ -80,6 +77,20 @@ func RepoPath(ctx context.Context, source string, head string) (chan Commit, err
|
|||
}()
|
||||
|
||||
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)
|
||||
for {
|
||||
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 {
|
||||
commitChan <- *currentCommit
|
||||
}
|
||||
if err := cmd.Wait(); err != nil {
|
||||
log.WithError(err).Debugf("Error waiting for git command to complete.")
|
||||
}
|
||||
close(commitChan)
|
||||
}()
|
||||
return commitChan, nil
|
||||
}
|
||||
|
||||
// Date: Tue Aug 10 15:20:40 2021 +0100
|
||||
|
|
Loading…
Reference in a new issue