Skip to content

Commit

Permalink
glock sync: only "go get" if the package doesn't yet exist.
Browse files Browse the repository at this point in the history
2x speedup for sync on GOPATH that's all OK
  • Loading branch information
robfig committed Sep 14, 2014
1 parent 3072357 commit 2e44814
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
13 changes: 8 additions & 5 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ func runSync(cmd *Command, args []string) {
var importDir = filepath.Join(gopath(), "src", importPath)

// Try to find the repo.
// go get it beforehand just in case it doesn't exist. (no-op if it does exist)
// (ignore failures due to "no buildable files" or build errors in the package.)
var getOutput, _ = run("go", "get", "-v", "-d", importPath)
var getOutput []byte
var repo, err = glockRepoRootForImportPath(importPath)
if err != nil {
fmt.Println(string(getOutput)) // in case the get failed due to connection error
perror(err)
// go get it in case it doesn't exist. (no-op if it does exist)
// (ignore failures due to "no buildable files" or build errors in the package.)
getOutput, _ = run("go", "get", "-v", "-d", importPath)
repo, err = glockRepoRootForImportPath(importPath)
if err != nil {
perror(err)
}
}

var maybeGot = ""
Expand Down
19 changes: 13 additions & 6 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ import (

// glockRepoRootForImportPath wraps the vcs.go version. If the stock one
// doesn't work, it looks for .git, .hg directories up to the tree.
// This is done to support repos with non-go-get friendly names.
// Also, returns an error if it doesn't exist (e.g. it needs to be go gotten).
func glockRepoRootForImportPath(importPath string) (*repoRoot, error) {
var rr, err = repoRootForImportPath(importPath)
if err == nil {
return rr, nil
}

pkg, err := build.Import(importPath, "", build.FindOnly)
var pkg, err = build.Import(importPath, "", build.FindOnly)
if err != nil {
return nil, err
}

rr, err := repoRootForImportPath(importPath)
if err == nil {
// it may not exist, even with err == nil
_, err = os.Stat(pkg.Dir)
if err != nil {
return nil, err
}
return rr, nil
}

var dir = pkg.Dir
var rootImportPath = pkg.ImportPath
for len(dir) > 1 {
Expand Down

0 comments on commit 2e44814

Please sign in to comment.