From b410be31b6925ed3c084fe6855224acfbdf1af84 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 16 Sep 2010 13:45:40 -0700 Subject: [PATCH] godoc: show "Last update" info for directory listings. Use -timestamps=false flag to disable. (This used to be shown on the front-page below the build information with the old godoc. However, the time stamps are directory-specific and should be shown with the directory.) R=rsc CC=golang-dev https://golang.org/cl/2233044 --- src/cmd/godoc/doc.go | 2 ++ src/cmd/godoc/godoc.go | 59 +++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/cmd/godoc/doc.go b/src/cmd/godoc/doc.go index ad855cd54a..d0a4d73994 100644 --- a/src/cmd/godoc/doc.go +++ b/src/cmd/godoc/doc.go @@ -45,6 +45,8 @@ The flags are: print (exported) source in command-line mode -tabwidth=4 width of tabs in units of spaces + -timestamps=true + show timestamps with directory listings -path="" additional package directories (colon-separated) -html diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index cd3d14ede4..4abcf89405 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -58,7 +58,8 @@ var ( filterDelay delayTime // actual filter update interval in minutes; usually filterDelay == filterMin, but filterDelay may back off exponentially // layout control - tabwidth = flag.Int("tabwidth", 4, "tab width") + tabwidth = flag.Int("tabwidth", 4, "tab width") + showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings") // file system mapping fsMap Mapping // user-defined mapping @@ -100,13 +101,6 @@ func isParentOf(p, q string) bool { } -// isRelated returns true if p is a parent or child of (or the same as) q -// where p and q are directory paths. -func isRelated(p, q string) bool { - return isParentOf(p, q) || isParentOf(q, p) -} - - // binarySearch returns an index i such that (a[i] <= s < a[i+1]) || (s is not in a). // The slice a must not be empty and sorted in increasing order. // (See "A Method of Programming", E.W. Dijkstra). @@ -800,26 +794,23 @@ func readTemplates() { func servePage(c *http.Conn, title, subtitle, query string, content []byte) { type Data struct { - Title string - Subtitle string - PkgRoots []string - Timestamp int64 - Query string - Version string - Menu []byte - Content []byte + Title string + Subtitle string + PkgRoots []string + Query string + Version string + Menu []byte + Content []byte } - _, ts := fsTree.get() d := Data{ - Title: title, - Subtitle: subtitle, - PkgRoots: fsMap.PrefixList(), - Timestamp: ts * 1e9, // timestamp in ns - Query: query, - Version: runtime.Version(), - Menu: nil, - Content: content, + Title: title, + Subtitle: subtitle, + PkgRoots: fsMap.PrefixList(), + Query: query, + Version: runtime.Version(), + Menu: nil, + Content: content, } if err := godocHTML.Execute(&d, c); err != nil { @@ -1101,6 +1092,7 @@ type PageInfo struct { PAst *ast.File // nil if no single AST with package exports PDoc *doc.PackageDoc // nil if no single package documentation Dirs *DirList // nil if no directory information + DirTime int64 // directory time stamp in seconds since epoch IsPkg bool // false if this is not documenting a real package Err os.Error // directory read error or nil } @@ -1207,11 +1199,13 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf // get directory information var dir *Directory - if tree, _ := fsTree.get(); tree != nil && tree.(*Directory) != nil { + var timestamp int64 + if tree, ts := fsTree.get(); tree != nil && tree.(*Directory) != nil { // directory tree is present; lookup respective directory // (may still fail if the file system was updated and the // new directory tree has not yet been computed) dir = tree.(*Directory).lookup(abspath) + timestamp = ts } if dir == nil { // the path may refer to a user-specified file system mapped @@ -1230,8 +1224,9 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf // found a RWValue associated with a user-specified file // system; a non-nil RWValue stores a (possibly out-of-date) // directory tree for that file system - if tree, _ := v.get(); tree != nil && tree.(*Directory) != nil { + if tree, ts := v.get(); tree != nil && tree.(*Directory) != nil { dir = tree.(*Directory).lookup(abspath) + timestamp = ts } } } @@ -1241,9 +1236,10 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf // note: cannot use path filter here because in general // it doesn't contain the fsTree path dir = newDirectory(abspath, nil, 1) + timestamp = time.Seconds() } - return PageInfo{abspath, plist, past, pdoc, dir.listing(true), h.isPkg, nil} + return PageInfo{abspath, plist, past, pdoc, dir.listing(true), timestamp, h.isPkg, nil} } @@ -1271,7 +1267,7 @@ func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) { return } - var title string + var title, subtitle string switch { case info.PAst != nil: title = "Package " + info.PAst.Name.Name @@ -1288,10 +1284,13 @@ func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) { } default: title = "Directory " + relativePath(info.Dirname) + if *showTimestamps { + subtitle = "Last update: " + time.SecondsToLocalTime(info.DirTime).String() + } } contents := applyTemplate(packageHTML, "packageHTML", info) - servePage(c, title, "", "", contents) + servePage(c, title, subtitle, "", contents) } -- 2.50.0