mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 13:14:22 +01:00
trying to split out work into goroutines
This commit is contained in:
1 parent
0e1ffaa573
commit
4654bc8ea5
1 file changed
+27
-5
@@ -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,21 +72,31 @@ 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) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
// iterate through commits
|
// iterate through commits
|
||||||
commits = bytes.Split(out, []byte("\n"))
|
commits = bytes.Split(out, []byte("\n"))
|
||||||
for j, commitB := range commits {
|
for j, commitB := range commits {
|
||||||
|
fmt.Println(branch, string(commitB), j)
|
||||||
if j == len(commits)-2 {
|
if j == len(commits)-2 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -95,6 +107,16 @@ func (repo Repo) audit() []ReportElem {
|
|||||||
string(commitB), string(commits[j+1])})
|
string(commitB), string(commits[j+1])})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
messages <- branch
|
||||||
|
}(branch)
|
||||||
|
go func() {
|
||||||
|
for i := range messages {
|
||||||
|
fmt.Println(i)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
return report
|
return report
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user