Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(283)

Delta Between Two Patch Sets: src/cmd/godoc/dirtrees.go

Issue 5699072: code review 5699072: godoc: don't show directories w/o packages in flat dir mode (Closed)
Left Patch Set: diff -r 81084c0ed4e8 https://code.google.com/p/go Created 13 years ago
Right Patch Set: diff -r f3f83fcdabfb https://code.google.com/p/go Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/godoc/package.txt ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // This file contains the code dealing with package directory trees. 5 // This file contains the code dealing with package directory trees.
6 6
7 package main 7 package main
8 8
9 import ( 9 import (
10 "bytes" 10 "bytes"
11 "go/doc" 11 "go/doc"
12 "go/parser" 12 "go/parser"
13 "go/token" 13 "go/token"
14 "log" 14 "log"
15 "os" 15 "os"
16 "path/filepath" 16 "path/filepath"
17 "strings" 17 "strings"
18 ) 18 )
19 19
20 // Conventional name for directories containing test data. 20 // Conventional name for directories containing test data.
21 // Excluded from directory trees. 21 // Excluded from directory trees.
22 // 22 //
23 const testdataDirName = "testdata" 23 const testdataDirName = "testdata"
24 24
25 type Directory struct { 25 type Directory struct {
26 Depth int 26 Depth int
27 Path string // directory path; includes Name 27 Path string // directory path; includes Name
28 Name string // directory name 28 Name string // directory name
29 HasPkg bool // true if the directory contains at least one pac kage 29 HasPkg bool // true if the directory contains at least one pac kage
bradfitz 2012/02/26 08:22:53 package or command? or just package? if the forme
Sameer Ajmani 2012/02/27 01:44:15 I'd color it HasFiles.
gri 2012/02/27 18:49:40 As the comments says: at least one package. And a
gri 2012/02/27 18:49:40 HasFiles is misleading. This is about .go files wh
30 Synopsis string // package documentation, if any 30 Synopsis string // package documentation, if any
31 Dirs []*Directory // subdirectories 31 Dirs []*Directory // subdirectories
32 } 32 }
33 33
34 func isGoFile(fi os.FileInfo) bool { 34 func isGoFile(fi os.FileInfo) bool {
35 name := fi.Name() 35 name := fi.Name()
36 return !fi.IsDir() && 36 return !fi.IsDir() &&
37 len(name) > 0 && name[0] != '.' && // ignore .files 37 len(name) > 0 && name[0] != '.' && // ignore .files
38 filepath.Ext(name) == ".go" 38 filepath.Ext(name) == ".go"
39 } 39 }
(...skipping 16 matching lines...) Expand all
56 56
57 func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i nt) *Directory { 57 func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i nt) *Directory {
58 if b.pathFilter != nil && !b.pathFilter(path) || name == testdataDirName { 58 if b.pathFilter != nil && !b.pathFilter(path) || name == testdataDirName {
59 return nil 59 return nil
60 } 60 }
61 61
62 if depth >= b.maxDepth { 62 if depth >= b.maxDepth {
63 // return a dummy directory so that the parent directory 63 // return a dummy directory so that the parent directory
64 // doesn't get discarded just because we reached the max 64 // doesn't get discarded just because we reached the max
65 // directory depth 65 // directory depth
66 » » return &Directory{depth, path, name, false, "", nil} 66 » » return &Directory{
bradfitz 2012/02/26 08:22:53 I think this passed the reasonable limit for tagle
Sameer Ajmani 2012/02/27 01:44:15 +1
gri 2012/02/27 18:49:40 Done.
gri 2012/02/27 18:49:40 Done.
67 » » » Depth: depth,
68 » » » Path: path,
69 » » » Name: name,
70 » » }
67 } 71 }
68 72
69 list, err := fs.ReadDir(path) 73 list, err := fs.ReadDir(path)
70 if err != nil { 74 if err != nil {
71 // newDirTree is called with a path that should be a package 75 // newDirTree is called with a path that should be a package
72 // directory; errors here should not happen, but if they do, 76 // directory; errors here should not happen, but if they do,
73 // we want to know about them 77 // we want to know about them
74 log.Printf("ReadDir(%s): %s", path, err) 78 log.Printf("ReadDir(%s): %s", path, err)
75 } 79 }
76 80
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 143 }
140 144
141 // select the highest-priority synopsis for the directory entry, if any 145 // select the highest-priority synopsis for the directory entry, if any
142 synopsis := "" 146 synopsis := ""
143 for _, synopsis = range synopses { 147 for _, synopsis = range synopses {
144 if synopsis != "" { 148 if synopsis != "" {
145 break 149 break
146 } 150 }
147 } 151 }
148 152
149 » return &Directory{depth, path, name, hasPkgFiles, synopsis, dirs} 153 » return &Directory{
bradfitz 2012/02/26 08:22:53 I'd spell this out too. Too many of these share t
gri 2012/02/27 18:49:40 Done.
154 » » Depth: depth,
155 » » Path: path,
156 » » Name: name,
157 » » HasPkg: hasPkgFiles,
158 » » Synopsis: synopsis,
159 » » Dirs: dirs,
160 » }
150 } 161 }
151 162
152 // newDirectory creates a new package directory tree with at most maxDepth 163 // newDirectory creates a new package directory tree with at most maxDepth
153 // levels, anchored at root. The result tree is pruned such that it only 164 // levels, anchored at root. The result tree is pruned such that it only
154 // contains directories that contain package files or that contain 165 // contains directories that contain package files or that contain
155 // subdirectories containing package files (transitively). If a non-nil 166 // subdirectories containing package files (transitively). If a non-nil
156 // pathFilter is provided, directory paths additionally must be accepted 167 // pathFilter is provided, directory paths additionally must be accepted
157 // by the filter (i.e., pathFilter(path) must be true). If a value >= 0 is 168 // by the filter (i.e., pathFilter(path) must be true). If a value >= 0 is
158 // provided for maxDepth, nodes at larger depths are pruned as well; they 169 // provided for maxDepth, nodes at larger depths are pruned as well; they
159 // are assumed to contain package files even if their contents are not known 170 // are assumed to contain package files even if their contents are not known
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 317 }
307 p.Path = path 318 p.Path = path
308 p.Name = d.Name 319 p.Name = d.Name
309 p.HasPkg = d.HasPkg 320 p.HasPkg = d.HasPkg
310 p.Synopsis = d.Synopsis 321 p.Synopsis = d.Synopsis
311 i++ 322 i++
312 } 323 }
313 324
314 return &DirList{maxHeight, list} 325 return &DirList{maxHeight, list}
315 } 326 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b