]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: better handling of deep directory trees
authorRobert Griesemer <gri@golang.org>
Wed, 15 Sep 2010 01:58:09 +0000 (18:58 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 15 Sep 2010 01:58:09 +0000 (18:58 -0700)
also: fix a logic error with filter use at startup

R=rsc
CC=golang-dev
https://golang.org/cl/2184044

src/cmd/godoc/dirtrees.go
src/cmd/godoc/godoc.go
src/cmd/godoc/main.go

index d76fb99a1152d7dd64ad970731ac1c999368d2de..028bae99d332564e3e732cf49890e5eba2f0cecd 100644 (file)
@@ -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)
 }
index 484098323590f33c2d69e076a0bcb0aad6452ca7..59f4a95dbd356fa57b0ddb39bbe3306d1d601425 100644 (file)
@@ -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}
index 028c8a063106cccea2fd58ed454be67a6a863875..c13979968a453f9bf691571f6702d3397d1b3601 100644 (file)
@@ -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()