trying to split out work into goroutines

This commit is contained in:
zricethezav committed 2018-01-29 22:06:34 -05:00
1 parent 0e1ffaa573
commit 4654bc8ea5
1 file changed
+39 -17
+39 -17
View File
@@ -9,6 +9,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"sync"
) )
type ReportElem struct { type ReportElem struct {
@@ -61,6 +62,7 @@ func (repo Repo) audit() []ReportElem {
branch string branch string
commits [][]byte commits [][]byte
leaks []string leaks []string
wg sync.WaitGroup
) )
out, err = exec.Command("git", "branch", "--all").Output() out, err = exec.Command("git", "branch", "--all").Output()
@@ -70,31 +72,51 @@ func (repo Repo) audit() []ReportElem {
// iterate through branches, git rev-list <branch> // iterate through branches, git rev-list <branch>
branches := bytes.Split(out, []byte("\n")) branches := bytes.Split(out, []byte("\n"))
messages := make(chan string)
wg.Add(len(branches) - 3)
for i, branchB := range branches { for i, branchB := range branches {
if i < 2 || i == len(branches)-1 { if i < 2 || i == len(branches)-1 {
continue continue
} }
// if err := os.Chdir(repo.name); err != nil {
// log.Fatal(err)
// }
branch = string(bytes.Trim(branchB, " ")) branch = string(bytes.Trim(branchB, " "))
out, err = exec.Command("git", "rev-list", branch).Output() go func(branch string) {
if err != nil { defer wg.Done()
continue cmd := exec.Command("git", "rev-list", branch)
}
// iterate through commits if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repo.name)); err != nil {
commits = bytes.Split(out, []byte("\n")) log.Fatal(err)
for j, commitB := range commits {
if j == len(commits)-2 {
break
} }
leaks = checkDiff(string(commitB), string(commits[j+1])) out, err := cmd.Output()
if len(leaks) != 0 { if err != nil {
report = append(report, ReportElem{leaks, branch, log.Fatal(err)
string(commitB), string(commits[j+1])})
} }
} // iterate through commits
commits = bytes.Split(out, []byte("\n"))
for j, commitB := range commits {
fmt.Println(branch, string(commitB), j)
if j == len(commits)-2 {
break
}
leaks = checkDiff(string(commitB), string(commits[j+1]))
if len(leaks) != 0 {
report = append(report, ReportElem{leaks, branch,
string(commitB), string(commits[j+1])})
}
}
messages <- branch
}(branch)
go func() {
for i := range messages {
fmt.Println(i)
}
}()
} }
wg.Wait()
return report return report
} }