Documentation
¶
Overview ¶
Package sourceset says which of a repo's tracked files are source for init: it leaves out what git or the repo marks (vendored, generated), binary files and lock files, applies the test, doc and other patterns a session named, and resolves path claims so each file goes to the most specific one. It also writes the listings of those files that init's sessions read, and cuts them into parts by size.
Index ¶
- Constants
- func Brief(name, promise string, files []string) string
- func Claims(files []string, claims []Claim) (where map[string]string, missing []string, twice map[string][]string)
- func FileCount(n int) string
- func Kinds(files []File) string
- func Label(dir string) string
- func Match(pattern, file string) bool
- func Overview(files []File) string
- func Specificity(pattern, file string) int
- func Tree(files []File) string
- type Claim
- type Division
- type File
- type Kind
- type Listing
- type Part
Constants ¶
const ( LeftVendored = "vendored" LeftGenerated = "generated" LeftBinary = "binary" LeftLock = "lock" LeftNotAFile = "not a file" )
Reasons a file is left out of a Listing.
Variables ¶
This section is empty.
Functions ¶
func Brief ¶
Brief is one line saying what an area holds: its name, promise, file count and the six folders holding most of its files.
func Claims ¶
func Claims(files []string, claims []Claim) (where map[string]string, missing []string, twice map[string][]string)
Claims resolves which owner each file goes to: the owner whose pattern on it is most specific. When two different owners tie at the highest specificity the file is claimed twice: it is in twice with its owners sorted, and in no owner of where. A file no pattern matches is missing. Files keep their input order.
func Kinds ¶
Kinds lists every folder with its file count and a tally of the file extensions in it, such as "spec/models/ (40 files: .rb 40)", for the session that names the files that are not source.
func Match ¶
Match reports whether pattern names file. A leading "./" or "/" is trimmed and an empty pattern matches nothing. "dir/" matches every file under a folder named dir at any depth, as in .gitignore, and "a/dir/" every file under that path from the root. A pattern with no "/" matches the base name in any folder, and a glob-free one also names a folder at the root. Otherwise segments are matched one by one with path.Match, and a "**" segment matches zero or more segments. A literal path matches that file, or every file under it when it names a folder. A malformed pattern matches nothing.
func Specificity ¶
Specificity says how closely pattern names file: 0 for no match, the highest value for the file's exact path, otherwise the length of the pattern's literal prefix before its first "*", "?" or "[" (for "dir/", its length) plus 1.
Types ¶
type Division ¶
type Division struct {
// Tests, Docs and Other are the patterns as given.
Tests, Docs, Other []string
// Files holds the paths of each kind, in input order.
Files map[Kind][]string
// Unused are the patterns that matched no file, kept and reported.
Unused []string
// Dropped are the patterns that matched every listed file, left out
// before the split.
Dropped []string
}
Division is the result of Split.
func Split ¶
Split sorts files into tests, docs, other and source. Each file goes to the kind with the most specific matching pattern, a tie going to the first kind in that order, and a file matching none is source. A pattern that matches no file is reported in Unused; one that matches every file is dropped and reported in Dropped, since it would leave no source.
type File ¶
type File struct {
// Path is the slash path from the repo root.
Path string
// Lines is the number of newlines in the file.
Lines int
}
File is a source candidate: a tracked file that was not left out.
type Listing ¶
type Listing struct {
Files []File
// Left maps a reason (the Left constants) to the paths left out for it.
Left map[string][]string
}
Listing is the files kept and, by reason, the paths left out.
type Part ¶
Part is one cut of the source listing: its text and the files it names.
func Cut ¶
Cut cuts the Tree's lines into parts of at most size characters. It never cuts inside a folder's line, keeps consecutive folders sharing their first two path segments together when they fit, and gives a line larger than size a part of its own. Every file is in exactly one part. It only cuts for size: it never groups files by what they do.