From 4654bc8ea5d54c8a92496f2df37ce55ed0480d20 Mon Sep 17 00:00:00 2001 From: zricethezav Date: Mon, 29 Jan 2018 22:06:34 -0500 Subject: [PATCH] trying to split out work into goroutines --- repo.go | 56 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/repo.go b/repo.go index 93318039..a5e45db2 100644 --- a/repo.go +++ b/repo.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "strings" + "sync" ) type ReportElem struct { @@ -61,6 +62,7 @@ func (repo Repo) audit() []ReportElem { branch string commits [][]byte leaks []string + wg sync.WaitGroup ) out, err = exec.Command("git", "branch", "--all").Output() @@ -70,31 +72,51 @@ func (repo Repo) audit() []ReportElem { // iterate through branches, git rev-list branches := bytes.Split(out, []byte("\n")) + + messages := make(chan string) + wg.Add(len(branches) - 3) + for i, branchB := range branches { if i < 2 || i == len(branches)-1 { continue } - // if err := os.Chdir(repo.name); err != nil { - // log.Fatal(err) - // } branch = string(bytes.Trim(branchB, " ")) - out, err = exec.Command("git", "rev-list", branch).Output() - if err != nil { - continue - } - // iterate through commits - commits = bytes.Split(out, []byte("\n")) - for j, commitB := range commits { - if j == len(commits)-2 { - break + go func(branch string) { + defer wg.Done() + cmd := exec.Command("git", "rev-list", branch) + + if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repo.name)); err != nil { + log.Fatal(err) } - leaks = checkDiff(string(commitB), string(commits[j+1])) - if len(leaks) != 0 { - report = append(report, ReportElem{leaks, branch, - string(commitB), string(commits[j+1])}) + out, err := cmd.Output() + if err != nil { + log.Fatal(err) } - } + // 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 }