Skip to content

Commit

Permalink
avoid processing deps multiple times when computing rewrite paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jun 12, 2018
1 parent 964260e commit 25e446b
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,23 +1017,32 @@ func addRewriteForDep(dep *gx.Dependency, pkg *Package, m map[string]string, und
}

func buildRewriteMapping(pkg *Package, pkgdir string, m map[string]string, undo bool) error {
for _, dep := range pkg.Dependencies {
cpkg, err := loadDep(dep, pkgdir)
if err != nil {
VLog("error loading dep %q of %q: %s", dep.Name, pkg.Name, err)
return fmt.Errorf("package %q not found. (dependency of %s)", dep.Name, pkg.Name)
}
seen := make(map[string]struct{})
var process func(pkg *Package) error
process = func(pkg *Package) error {
for _, dep := range pkg.Dependencies {
if _, ok := seen[dep.Hash]; ok {
continue
}
seen[dep.Hash] = struct{}{}

addRewriteForDep(dep, cpkg, m, undo)
cpkg, err := loadDep(dep, pkgdir)
if err != nil {
VLog("error loading dep %q of %q: %s", dep.Name, pkg.Name, err)
return fmt.Errorf("package %q not found. (dependency of %s)", dep.Name, pkg.Name)
}

// recurse!
err = buildRewriteMapping(cpkg, pkgdir, m, undo)
if err != nil {
return err
addRewriteForDep(dep, cpkg, m, undo)

// recurse!
err = process(cpkg)
if err != nil {
return err
}
}
return nil
}

return nil
return process(pkg)
}

func buildMap(pkg *Package, m map[string]string) error {
Expand Down

0 comments on commit 25e446b

Please sign in to comment.