Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Addressed most MR comments. Still struggling with the new concurrency…
Browse files Browse the repository at this point in the history
… requests
  • Loading branch information
xmattstrongx committed Oct 12, 2017
1 parent 4f991d4 commit c0c8ef8
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions cmd/dep/root_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ import (
"context"
"io/ioutil"
"log"
"strings"

"golang.org/x/sync/errgroup"

"github.com/golang/dep"
fb "github.com/golang/dep/internal/feedback"
"github.com/golang/dep/internal/gps"
"github.com/golang/dep/internal/gps/paths"
"github.com/golang/dep/internal/importers"
)

const concurrency = 4

// rootAnalyzer supplies manifest/lock data from both dep and external tool's
// configuration files.
// * When used on the root project, it imports only from external tools.
Expand Down Expand Up @@ -64,9 +60,9 @@ func (a *rootAnalyzer) InitializeRootManifestAndLock(dir string, pr gps.ProjectR
}

func (a *rootAnalyzer) cacheDeps(pr gps.ProjectRoot) error {
deps := make(map[gps.ProjectRoot]bool)
logger := a.ctx.Err
g, ctx := errgroup.WithContext(context.TODO())
concurrency := 4
sem := make(chan struct{}, concurrency)

syncDep := func(pr gps.ProjectRoot, sm gps.SourceManager) error {
Expand All @@ -80,48 +76,28 @@ func (a *rootAnalyzer) cacheDeps(pr gps.ProjectRoot) error {

for ip := range a.directDeps {
logger.Printf("Package %q, analyzing...", ip)
if paths.IsStandardImportPath(ip) {
continue
}
if hasImportPathPrefix(ip, string(pr)) {
continue
}

pr, err := a.sm.DeduceProjectRoot(ip)
if err != nil {
return err
}

if _, ok := deps[pr]; ok {
continue
}

g.Go(func() error {
select {
case sem <- struct{}{}:
defer func() { <-sem }()
case <-ctx.Done():
return ctx.Err()
}
err := syncDep(pr, a.sm)
return err
return syncDep(pr, a.sm)
})

deps[pr] = true
}
if err := g.Wait(); err == nil {
logger.Printf("Successfully cached all deps.")
if err := g.Wait(); err != nil {
return err
}
logger.Printf("Successfully cached all deps.")
return nil
}

func hasImportPathPrefix(s, prefix string) bool {
if s == prefix {
return true
}
return strings.HasPrefix(s, prefix+"/")
}

func (a *rootAnalyzer) importManifestAndLock(dir string, pr gps.ProjectRoot, suppressLogs bool) (*dep.Manifest, *dep.Lock, error) {
logger := a.ctx.Err
if suppressLogs {
Expand Down

0 comments on commit c0c8ef8

Please sign in to comment.