mirror of
https://github.com/golang/go
synced 2024-11-18 19:54:44 -07:00
imports: minor fixes
These are mostly comments for CL 24941 that didn't get sent quickly enough. strings.Trim(`\"`) works, but by accident. It trims all leading and trailing "s and \s, but there are never leading or trailing \s. Semantic line breaks and punctuation cleanup. The reflow of comments in the pkgName == "main" if block is to silence this spurious vet failure: fix.go:247: +build comment must appear before package clause and be followed by a blank line Plain sync.Once values are enough. Change-Id: I241f3025031b6f21605da78ea52066713a203327 Reviewed-on: https://go-review.googlesource.com/24983 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
c550f66b0b
commit
6d32be89d5
@ -83,7 +83,7 @@ func fixImports(fset *token.FileSet, f *ast.File, filename string) (added []stri
|
|||||||
decls[v.Name.Name] = v
|
decls[v.Name.Name] = v
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
ipath := strings.Trim(v.Path.Value, `\"`)
|
ipath := strings.Trim(v.Path.Value, `"`)
|
||||||
if ipath == "C" {
|
if ipath == "C" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ func importPathToNameBasic(importPath, srcDir string) (packageName string) {
|
|||||||
// importPathToNameGoPath finds out the actual package name, as declared in its .go files.
|
// importPathToNameGoPath finds out the actual package name, as declared in its .go files.
|
||||||
// If there's a problem, it falls back to using importPathToNameBasic.
|
// If there's a problem, it falls back to using importPathToNameBasic.
|
||||||
func importPathToNameGoPath(importPath, srcDir string) (packageName string) {
|
func importPathToNameGoPath(importPath, srcDir string) (packageName string) {
|
||||||
// Fast path for standard library without going to disk:
|
// Fast path for standard library without going to disk.
|
||||||
if pkg, ok := stdImportPackage[importPath]; ok {
|
if pkg, ok := stdImportPackage[importPath]; ok {
|
||||||
return pkg
|
return pkg
|
||||||
}
|
}
|
||||||
@ -243,10 +243,8 @@ func importPathToNameGoPathParse(importPath, srcDir string) (packageName string,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if pkgName == "main" {
|
if pkgName == "main" {
|
||||||
// Also skip package main, assuming it's a
|
// Also skip package main, assuming it's a +build ignore generator or example.
|
||||||
// +build ignore generator or example. Since
|
// Since you can't import a package main anyway, there's no harm here.
|
||||||
// you can't import a package main anyway,
|
|
||||||
// there's no harm here.
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return pkgName, nil
|
return pkgName, nil
|
||||||
@ -272,9 +270,9 @@ func init() {
|
|||||||
// Directory-scanning state.
|
// Directory-scanning state.
|
||||||
var (
|
var (
|
||||||
// scanGoRootOnce guards calling scanGoRoot (for $GOROOT)
|
// scanGoRootOnce guards calling scanGoRoot (for $GOROOT)
|
||||||
scanGoRootOnce = &sync.Once{}
|
scanGoRootOnce sync.Once
|
||||||
// scanGoPathOnce guards calling scanGoPath (for $GOPATH)
|
// scanGoPathOnce guards calling scanGoPath (for $GOPATH)
|
||||||
scanGoPathOnce = &sync.Once{}
|
scanGoPathOnce sync.Once
|
||||||
|
|
||||||
dirScanMu sync.RWMutex
|
dirScanMu sync.RWMutex
|
||||||
dirScan map[string]*pkg // abs dir path => *pkg
|
dirScan map[string]*pkg // abs dir path => *pkg
|
||||||
@ -615,8 +613,8 @@ func loadExportsGoPath(expectPackage, dir string) map[string]bool {
|
|||||||
// to satisfy uses of pkg.X in the file.
|
// to satisfy uses of pkg.X in the file.
|
||||||
var findImport func(pkgName string, symbols map[string]bool, filename string) (foundPkg string, rename bool, err error) = findImportGoPath
|
var findImport func(pkgName string, symbols map[string]bool, filename string) (foundPkg string, rename bool, err error) = findImportGoPath
|
||||||
|
|
||||||
// findImportGoPath is the normal implementation of findImport. (Some
|
// findImportGoPath is the normal implementation of findImport.
|
||||||
// companies have their own internally)
|
// (Some companies have their own internally.)
|
||||||
func findImportGoPath(pkgName string, symbols map[string]bool, filename string) (foundPkg string, rename bool, err error) {
|
func findImportGoPath(pkgName string, symbols map[string]bool, filename string) (foundPkg string, rename bool, err error) {
|
||||||
// Fast path for the standard library.
|
// Fast path for the standard library.
|
||||||
// In the common case we hopefully never have to scan the GOPATH, which can
|
// In the common case we hopefully never have to scan the GOPATH, which can
|
||||||
|
@ -982,8 +982,8 @@ type Buffer2 struct {}
|
|||||||
|
|
||||||
func withEmptyGoPath(fn func()) {
|
func withEmptyGoPath(fn func()) {
|
||||||
dirScanMu.Lock()
|
dirScanMu.Lock()
|
||||||
scanGoRootOnce = &sync.Once{}
|
scanGoRootOnce = sync.Once{}
|
||||||
scanGoPathOnce = &sync.Once{}
|
scanGoPathOnce = sync.Once{}
|
||||||
dirScan = nil
|
dirScan = nil
|
||||||
ignoredDirs = nil
|
ignoredDirs = nil
|
||||||
dirScanMu.Unlock()
|
dirScanMu.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user