Commit b410be31 authored by Robert Griesemer's avatar Robert Griesemer

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
parent d19fcd07
......@@ -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
......
......@@ -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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment