diff --git a/godepfile.go b/godepfile.go index b09d80a..9d267f5 100644 --- a/godepfile.go +++ b/godepfile.go @@ -25,10 +25,6 @@ type Godeps struct { isOldFile bool } -func createGodepsFile() (*os.File, error) { - return os.Create(godepsFile) -} - func loadGodepsFile(path string) (Godeps, error) { var g Godeps f, err := os.Open(path) @@ -201,9 +197,7 @@ func (g *Godeps) addOrUpdateDeps(deps []Dependency) { missing = append(missing, d) } } - for _, d := range missing { - g.Deps = append(g.Deps, d) - } + g.Deps = append(g.Deps, missing...) } func (g *Godeps) removeDeps(deps []Dependency) { diff --git a/license.go b/license.go index d382063..5ce8249 100644 --- a/license.go +++ b/license.go @@ -51,7 +51,7 @@ func IsLegalFile(filename string) bool { } } for _, substring := range LegalFileSubstring { - if strings.Index(lowerfile, substring) != -1 { + if strings.Contains(lowerfile, substring) { return true } } diff --git a/list.go b/list.go index 40abbb5..283ed5d 100644 --- a/list.go +++ b/list.go @@ -54,10 +54,7 @@ func (ds *depScanner) Next() (*build.Package, string) { // Continue looping? func (ds *depScanner) Continue() bool { - if len(ds.todo) > 0 { - return true - } - return false + return len(ds.todo) > 0 } // Add a package and imports to the depScanner. Skips already processed/pending package/import combos @@ -94,7 +91,7 @@ func fullPackageInDir(dir string) (*build.Package, error) { var err error pkg, ok := pkgCache[dir] if !ok { - pkg, err = build.ImportDir(dir, build.FindOnly) + pkg, _ = build.ImportDir(dir, build.FindOnly) if pkg.Goroot { pkg, err = build.ImportDir(pkg.Dir, 0) } else { diff --git a/msg.go b/msg.go index 4a60378..8756904 100644 --- a/msg.go +++ b/msg.go @@ -27,29 +27,9 @@ func debugf(format string, a ...interface{}) (int, error) { return 0, nil } -func verbosef(format string, a ...interface{}) { - if verbose { - log.Printf(format, a...) - } -} - -func pp(a ...interface{}) (int, error) { - if debug { - return pretty.Print(a...) - } - return 0, nil -} - func ppln(a ...interface{}) (int, error) { if debug { return pretty.Println(a...) } return 0, nil } - -func ppf(format string, a ...interface{}) (int, error) { - if debug { - return pretty.Printf(format, a...) - } - return 0, nil -} diff --git a/rewrite.go b/rewrite.go index c4c8594..f19613a 100644 --- a/rewrite.go +++ b/rewrite.go @@ -98,6 +98,9 @@ func rewriteGoFile(name, qual string, paths []string) error { } fset = token.NewFileSet() f, err = parser.ParseFile(fset, name, &buffer, parser.ParseComments) + if err != nil { + return err + } ast.SortImports(fset, f) tpath := name + ".temp" t, err := os.Create(tpath) diff --git a/util.go b/util.go index df59786..00c58d1 100644 --- a/util.go +++ b/util.go @@ -1,35 +1,11 @@ package main import ( - "fmt" - "os/exec" "path/filepath" "runtime" "strings" ) -// Runs a command in dir. -// The name and args are as in exec.Command. -// Stdout, stderr, and the environment are inherited -// from the current process. -func runIn(dir, name string, args ...string) error { - _, err := runInWithOutput(dir, name, args...) - return err -} - -func runInWithOutput(dir, name string, args ...string) (string, error) { - c := exec.Command(name, args...) - c.Dir = dir - o, err := c.CombinedOutput() - - if debug { - fmt.Printf("execute: %+v\n", c) - fmt.Printf(" output: %s\n", string(o)) - } - - return string(o), err -} - // driveLetterToUpper converts Windows path's drive letters to uppercase. This // is needed when comparing 2 paths with different drive letter case. func driveLetterToUpper(path string) string { diff --git a/vcs.go b/vcs.go index 5d4a163..4d69b1a 100644 --- a/vcs.go +++ b/vcs.go @@ -79,19 +79,6 @@ func VCSFromDir(dir, srcRoot string) (*VCS, string, error) { return vcsext, reporoot, nil } -// VCSForImportPath returns a VCS value for an import path. -func VCSForImportPath(importPath string) (*VCS, error) { - rr, err := vcs.RepoRootForImportPath(importPath, debug) - if err != nil { - return nil, err - } - vcs := cmd[rr.VCS] - if vcs == nil { - return nil, fmt.Errorf("%s is unsupported: %s", rr.VCS.Name, importPath) - } - return vcs, nil -} - func (v *VCS) identify(dir string) (string, error) { out, err := v.runOutput(dir, v.IdentifyCmd) return string(bytes.TrimSpace(out)), err @@ -260,22 +247,6 @@ func expand(m map[string]string, s string) string { return s } -// Mercurial has no command equivalent to git remote add. -// We handle it as a special case in process. -func hgLink(dir, remote, url string) error { - hgdir := filepath.Join(dir, ".hg") - if err := os.MkdirAll(hgdir, 0777); err != nil { - return err - } - path := filepath.Join(hgdir, "hgrc") - f, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666) - if err != nil { - return err - } - fmt.Fprintf(f, "[paths]\n%s = %s\n", remote, url) - return f.Close() -} - func gitDetached(r string) (bool, error) { o, err := vcsGit.runOutput(r, "status") if err != nil {