sourceset

package
v0.0.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Brief(name, promise string, files []string) string

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 FileCount

func FileCount(n int) string

FileCount is n files as the listings write it: "1 file", "3 files".

func Kinds

func Kinds(files []File) string

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 Label

func Label(dir string) string

Label is a folder as the listings write it: root files sit under "./".

func Match

func Match(pattern, file string) bool

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 Overview

func Overview(files []File) string

Overview lists every folder with its counts and no file names.

func Specificity

func Specificity(pattern, file string) int

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.

func Tree

func Tree(files []File) string

Tree lists every folder on one line: "dir/ (N files, L lines): a.go b.go". Folders are sorted and root files sit under "./". The same files always give the same text.

Types

type Claim

type Claim struct {
	Owner    string
	Patterns []string
}

Claim is the path patterns one owner says are its own.

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

func Split(files []File, tests, docs, other []string) Division

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.

func Only

func Only(files []File, paths []string) []File

Only is the files whose paths are in paths, in the order of files.

type Kind

type Kind string

Kind says what a file is for init.

const (
	Test   Kind = "test"
	Doc    Kind = "doc"
	Other  Kind = "other"
	Source Kind = "source"
)

The kinds, in the order a tie between patterns is settled.

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.

func List

func List(root string, files []vcs.TrackedFile) (Listing, error)

List reads the tracked files under root and keeps those that are text, not marked vendored or generated, not lock files and regular. Paths stay slash paths and the order of files is kept.

type Part

type Part struct {
	Text  string
	Files []string
}

Part is one cut of the source listing: its text and the files it names.

func Cut

func Cut(files []File, size int) []Part

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL