mirror of
https://github.com/golang/go
synced 2024-11-25 06:57:58 -07:00
godoc: better handling of deep directory trees
also: fix a logic error with filter use at startup R=rsc CC=golang-dev https://golang.org/cl/2184044
This commit is contained in:
parent
4398768b84
commit
7f0ddd682a
@ -171,24 +171,24 @@ func (b *treeBuilder) newDirTree(path, name string, depth int) *Directory {
|
||||
}
|
||||
|
||||
|
||||
// Maximum directory depth, adjust as needed.
|
||||
const maxDirDepth = 24
|
||||
|
||||
// newDirectory creates a new package directory tree with at most maxDepth
|
||||
// levels, anchored at root. The result tree is pruned such that it only
|
||||
// contains directories that contain package files or that contain
|
||||
// subdirectories containing package files (transitively). If a non-nil
|
||||
// pathFilter is provided, directory paths additionally must be accepted
|
||||
// by the filter (i.e., pathFilter(path) must be true). If maxDepth is
|
||||
// too shallow, the leaf nodes are assumed to contain package files even if
|
||||
// their contents are not known (i.e., in this case the tree may contain
|
||||
// directories w/o any package files).
|
||||
// by the filter (i.e., pathFilter(path) must be true). If a value >= 0 is
|
||||
// provided for maxDepth, nodes at larger depths are pruned as well; they
|
||||
// are assumed to contain package files even if their contents are not known
|
||||
// (i.e., in this case the tree may contain directories w/o any package files).
|
||||
//
|
||||
func newDirectory(root string, pathFilter func(string) bool, maxDepth int) *Directory {
|
||||
d, err := os.Lstat(root)
|
||||
if err != nil || !isPkgDir(d) {
|
||||
return nil
|
||||
}
|
||||
if maxDepth < 0 {
|
||||
maxDepth = 1e6 // "infinity"
|
||||
}
|
||||
b := treeBuilder{pathFilter, maxDepth}
|
||||
return b.newDirTree(root, d.Name, 0)
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ func updateFilterFile() {
|
||||
// for each user-defined file system mapping, compute
|
||||
// respective directory tree w/o filter for accuracy
|
||||
fsMap.Iterate(func(path string, value *RWValue) bool {
|
||||
value.set(newDirectory(path, nil, maxDirDepth))
|
||||
value.set(newDirectory(path, nil, -1))
|
||||
return true
|
||||
})
|
||||
|
||||
@ -194,7 +194,7 @@ func initDirTrees() {
|
||||
// for each user-defined file system mapping, compute
|
||||
// respective directory tree quickly using pathFilter
|
||||
go fsMap.Iterate(func(path string, value *RWValue) bool {
|
||||
value.set(newDirectory(path, getPathFilter(), maxDirDepth))
|
||||
value.set(newDirectory(path, getPathFilter(), -1))
|
||||
return true
|
||||
})
|
||||
|
||||
@ -1203,10 +1203,11 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf
|
||||
}
|
||||
}
|
||||
if dir == nil {
|
||||
// no directory tree present (either early after startup
|
||||
// or command-line mode, or we don't have a tree for the
|
||||
// directory yet; e.g. google3); compute one level for this page
|
||||
dir = newDirectory(abspath, getPathFilter(), 1)
|
||||
// no directory tree present (too early after startup or
|
||||
// command-line mode); compute one level for this page
|
||||
// note: cannot use path filter here because in general
|
||||
// it doesn't contain the fsTree path
|
||||
dir = newDirectory(abspath, nil, 1)
|
||||
}
|
||||
|
||||
return PageInfo{abspath, plist, past, pdoc, dir.listing(true), h.isPkg, nil}
|
||||
|
@ -127,7 +127,7 @@ func dosync(c *http.Conn, r *http.Request) {
|
||||
// TODO(gri): The directory tree may be temporarily out-of-sync.
|
||||
// Consider keeping separate time stamps so the web-
|
||||
// page can indicate this discrepancy.
|
||||
fsTree.set(newDirectory(*goroot, nil, maxDirDepth))
|
||||
fsTree.set(newDirectory(*goroot, nil, -1))
|
||||
fallthrough
|
||||
case 1:
|
||||
// sync failed because no files changed;
|
||||
@ -259,7 +259,7 @@ func main() {
|
||||
// 1) set timestamp right away so that the indexer is kicked on
|
||||
fsTree.set(nil)
|
||||
// 2) compute initial directory tree in a goroutine so that launch is quick
|
||||
go func() { fsTree.set(newDirectory(*goroot, nil, maxDirDepth)) }()
|
||||
go func() { fsTree.set(newDirectory(*goroot, nil, -1)) }()
|
||||
|
||||
// Initialize directory trees for user-defined file systems (-path flag).
|
||||
initDirTrees()
|
||||
|
Loading…
Reference in New Issue
Block a user