style: use linter to style the code
This commit is contained in:
parent
501e74967c
commit
4db46dd96f
1 changed files with 94 additions and 73 deletions
|
|
@ -8,19 +8,26 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
// add a mutex to safely increment shared counters
|
||||
var mu sync.Mutex
|
||||
|
||||
func checkoutRepositories(repositories []Repository, concurrency int) {
|
||||
|
||||
// create a waitgroup + semaphore channel
|
||||
var wg sync.WaitGroup
|
||||
semaphore := make(chan struct{}, concurrency)
|
||||
|
||||
// manage all repositories found
|
||||
for _, repo := range repositories {
|
||||
|
||||
// increment waitgroup counter + acquire semaphore slot
|
||||
wg.Add(1)
|
||||
semaphore <- struct{}{}
|
||||
|
||||
// start go routine per repo
|
||||
go func(repo Repository) {
|
||||
|
||||
// ensure we release the semaphore and close the goroutine
|
||||
defer func() {
|
||||
<-semaphore
|
||||
wg.Done()
|
||||
|
|
@ -63,6 +70,8 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
if err != nil {
|
||||
log.Printf("ERROR: %v\n", err)
|
||||
}
|
||||
|
||||
// set a lock, increment counters and unlock
|
||||
mu.Lock()
|
||||
clonedCount++
|
||||
mu.Unlock()
|
||||
|
|
@ -76,6 +85,8 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
default:
|
||||
log.Printf("ERROR: decided not to clone or pull repository %v\n", repoName)
|
||||
log.Printf("ERROR: this is why: %v\n", repoStatus)
|
||||
|
||||
// set a lock, increment counters and unlock
|
||||
mu.Lock()
|
||||
errorCount++
|
||||
mu.Unlock()
|
||||
|
|
@ -83,6 +94,8 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
}
|
||||
}(repo)
|
||||
}
|
||||
|
||||
// wait for goroutines
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
|
|
@ -109,11 +122,19 @@ func pullRepository(repoName string, repoDestination string) {
|
|||
// pull repository
|
||||
pullCmd := exec.Command("git", "-C", repoDestination, "pull", remote)
|
||||
pullOutput, err := pullCmd.CombinedOutput()
|
||||
pulledCount = pulledCount + 1
|
||||
|
||||
// set a lock, increment counters and unlock
|
||||
mu.Lock()
|
||||
pulledCount++
|
||||
mu.Unlock()
|
||||
|
||||
if err != nil {
|
||||
errorCount = errorCount + 1
|
||||
pulledCount = pulledCount - 1
|
||||
|
||||
// set a lock, increment counters and unlock
|
||||
mu.Lock()
|
||||
errorCount++
|
||||
pulledCount--
|
||||
mu.Unlock()
|
||||
|
||||
switch {
|
||||
case strings.Contains(string(pullOutput), "You have unstaged changes"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue