diff --git a/vcs.go b/vcs.go index e673de03..dc517319 100644 --- a/vcs.go +++ b/vcs.go @@ -6,7 +6,6 @@ import ( "os" "os/exec" "strings" - "sync" "time" ) @@ -143,25 +142,38 @@ func getCommit(url string, branch string, protocols []string) string { } func (infos shaInfos) needsUpdate() bool { - var wg sync.WaitGroup - hasUpdate := false + //used to signal we have gone through all sources and found nothing + finished := make(chan struct{}) + alive := 0 + + //if we find an update we use this to exit early and return true + hasUpdate := make(chan struct{}) checkHash := func(url string, info shaInfo) { - defer wg.Done() hash := getCommit(url, info.Brach, info.Protocols) if hash != "" && hash != info.SHA { - hasUpdate = true + hasUpdate <- struct{}{} + } else { + finished <- struct{}{} } } for url, info := range infos { - wg.Add(1) + alive++ go checkHash(url, info) } - wg.Wait() - - return hasUpdate + for { + select { + case <- hasUpdate: + return true + case <- finished: + alive-- + if alive == 0 { + return false + } + } + } } func inStore(pkgName string) shaInfos {