On this page
The directory walker and its worker pool: traversal filters, per-file classification and LOC counting, and deterministic per-format aggregation.
#internal/scan
#internal/scan
Package scan walks a directory tree, classifies files via a worker pool, and aggregates per-format statistics.
#SingletonsGroup
const SingletonsGroup = "(singletons)"SingletonsGroup is the format name of the pseudo-group produced by CollapseSingletons.
#IgnoredInclude
const IgnoredInclude = "include"Values for Options.Ignored.
#IgnoredExclude
const IgnoredExclude = "exclude"#IgnoredOnly
const IgnoredOnly = "only"#HiddenInclude
const HiddenInclude = "include"Values for Options.Hidden.
#HiddenExclude
const HiddenExclude = "exclude"#TypeText
const TypeText = "text"Values for Options.TypeFilter.
#TypeBinary
const TypeBinary = "binary"#TypeBoth
const TypeBoth = "both"#FormatsRaw
const FormatsRaw = classify.FormatsRawValues for Options.Formats.
#FormatsCanonical
const FormatsCanonical = classify.FormatsCanonical#StatNames
var StatNames = []string{Stat names accepted by --stats (canonical column order).
#Options
type Options structOptions configures a scan.
#Summary
type Summary structSummary holds the tree-wide summary statistics.
#Group
type Group structGroup is the aggregate statistics for one format.
#Result
type Result structResult is the outcome of a scan. Groups are ordered by format name ascending; callers apply their own sort.
#IsLOCStat
func IsLOCStat(name string) boolIsLOCStat reports whether name is one of the LOC stat names.
#SortGroups
func SortGroups(groups []Group, keys []string, desc bool)SortGroups sorts groups in place by the given keys ("format" or a stat name) in precedence order, all in the same direction (desc when desc is true). Ties are broken by format name ascending (case-insensitive, then case-sensitive) so the output is deterministic.
#CollapseSingletons
func CollapseSingletons(groups []Group) []GroupCollapseSingletons merges all groups with exactly one file into a single "(singletons)" pseudo-group: count is the number of merged groups, sizes are aggregated over all merged groups, and LOC values are aggregated over the text merged groups only. The input is not modified.
#Scan
func Scan(opts Options) (*Result, error)Scan walks opts.Root and returns aggregated statistics. It returns an error only if the root itself cannot be read; unreadable entries below the root are counted in Summary.Unreadable instead.
#ignoreMatcher.Match
func (im *ignoreMatcher) Match(rel string, isDir bool) boolMatch reports whether the slash-separated path relative to the scan root is gitignored.