aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-09-14 18:58:09 -0700
committerRobert Griesemer <gri@golang.org>2010-09-14 18:58:09 -0700
commit7f0ddd682aaf2b4d36b5f35eef13860c85f8f4fe (patch)
treec1bc3e74c941907f470522f7c31670933c790b55
parent4398768b849718836bc2efaa41409cf01aefe30b (diff)
downloadgo-7f0ddd682aaf2b4d36b5f35eef13860c85f8f4fe.tar.gz
go-7f0ddd682aaf2b4d36b5f35eef13860c85f8f4fe.zip
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
-rw-r--r--src/cmd/godoc/dirtrees.go14
-rw-r--r--src/cmd/godoc/godoc.go13
-rw-r--r--src/cmd/godoc/main.go4
3 files changed, 16 insertions, 15 deletions
diff --git a/src/cmd/godoc/dirtrees.go b/src/cmd/godoc/dirtrees.go
index d76fb99a11..028bae99d3 100644
--- a/src/cmd/godoc/dirtrees.go
+++ b/src/cmd/godoc/dirtrees.go
@@ -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)
}
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index 4840983235..59f4a95dbd 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -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}
diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go
index 028c8a0631..c13979968a 100644
--- a/src/cmd/godoc/main.go
+++ b/src/cmd/godoc/main.go
@@ -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()