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: ...@@ -45,6 +45,8 @@ The flags are:
print (exported) source in command-line mode print (exported) source in command-line mode
-tabwidth=4 -tabwidth=4
width of tabs in units of spaces width of tabs in units of spaces
-timestamps=true
show timestamps with directory listings
-path="" -path=""
additional package directories (colon-separated) additional package directories (colon-separated)
-html -html
......
...@@ -59,6 +59,7 @@ var ( ...@@ -59,6 +59,7 @@ var (
// layout control // 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 // file system mapping
fsMap Mapping // user-defined mapping fsMap Mapping // user-defined mapping
...@@ -100,13 +101,6 @@ func isParentOf(p, q string) bool { ...@@ -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). // 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. // The slice a must not be empty and sorted in increasing order.
// (See "A Method of Programming", E.W. Dijkstra). // (See "A Method of Programming", E.W. Dijkstra).
...@@ -803,19 +797,16 @@ func servePage(c *http.Conn, title, subtitle, query string, content []byte) { ...@@ -803,19 +797,16 @@ func servePage(c *http.Conn, title, subtitle, query string, content []byte) {
Title string Title string
Subtitle string Subtitle string
PkgRoots []string PkgRoots []string
Timestamp int64
Query string Query string
Version string Version string
Menu []byte Menu []byte
Content []byte Content []byte
} }
_, ts := fsTree.get()
d := Data{ d := Data{
Title: title, Title: title,
Subtitle: subtitle, Subtitle: subtitle,
PkgRoots: fsMap.PrefixList(), PkgRoots: fsMap.PrefixList(),
Timestamp: ts * 1e9, // timestamp in ns
Query: query, Query: query,
Version: runtime.Version(), Version: runtime.Version(),
Menu: nil, Menu: nil,
...@@ -1101,6 +1092,7 @@ type PageInfo struct { ...@@ -1101,6 +1092,7 @@ type PageInfo struct {
PAst *ast.File // nil if no single AST with package exports PAst *ast.File // nil if no single AST with package exports
PDoc *doc.PackageDoc // nil if no single package documentation PDoc *doc.PackageDoc // nil if no single package documentation
Dirs *DirList // nil if no directory information 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 IsPkg bool // false if this is not documenting a real package
Err os.Error // directory read error or nil Err os.Error // directory read error or nil
} }
...@@ -1207,11 +1199,13 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf ...@@ -1207,11 +1199,13 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf
// get directory information // get directory information
var dir *Directory 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 // directory tree is present; lookup respective directory
// (may still fail if the file system was updated and the // (may still fail if the file system was updated and the
// new directory tree has not yet been computed) // new directory tree has not yet been computed)
dir = tree.(*Directory).lookup(abspath) dir = tree.(*Directory).lookup(abspath)
timestamp = ts
} }
if dir == nil { if dir == nil {
// the path may refer to a user-specified file system mapped // 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 ...@@ -1230,8 +1224,9 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf
// found a RWValue associated with a user-specified file // found a RWValue associated with a user-specified file
// system; a non-nil RWValue stores a (possibly out-of-date) // system; a non-nil RWValue stores a (possibly out-of-date)
// directory tree for that file system // 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) dir = tree.(*Directory).lookup(abspath)
timestamp = ts
} }
} }
} }
...@@ -1241,9 +1236,10 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf ...@@ -1241,9 +1236,10 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf
// note: cannot use path filter here because in general // note: cannot use path filter here because in general
// it doesn't contain the fsTree path // it doesn't contain the fsTree path
dir = newDirectory(abspath, nil, 1) 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) { ...@@ -1271,7 +1267,7 @@ func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) {
return return
} }
var title string var title, subtitle string
switch { switch {
case info.PAst != nil: case info.PAst != nil:
title = "Package " + info.PAst.Name.Name title = "Package " + info.PAst.Name.Name
...@@ -1288,10 +1284,13 @@ func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) { ...@@ -1288,10 +1284,13 @@ func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) {
} }
default: default:
title = "Directory " + relativePath(info.Dirname) title = "Directory " + relativePath(info.Dirname)
if *showTimestamps {
subtitle = "Last update: " + time.SecondsToLocalTime(info.DirTime).String()
}
} }
contents := applyTemplate(packageHTML, "packageHTML", info) 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