Documentation
¶
Overview ¶
Package knowledge reports where the recent work on a directory was done by so few people that losing one of them loses most of what is known about it.
The figure ¶
The bus factor of a directory is the smallest number of people whose commits make up at least half of the commits that touched it in the history read. One means a single person made half or more of the recent changes there. Beside it the report gives the share held by the largest contributor and how long before the newest commit their last change there was, because "one person, and they stopped touching it eight months ago" is a different finding from "one person, yesterday".
A commit counts once for each directory it touches, whatever the number of files, so a directory's figures are drawn from commits and not from lines.
This names people, and what it may say about them is narrow ¶
Git records that somebody changed a file. It does not record that they understand it, that nobody else does, or that they are still here. The figure is a count of authorship in a bounded window, and every report carries that as data (Report.Caveats) so a renderer cannot print the names without printing what they mean. See internal/capability/ownership for the longer form of this argument; it applies here unchanged.
A person is a name, exactly as spelled ¶
People are grouped by the author name the history records and by nothing else. No identities are merged: deciding that "R. Vega" and "Robin Vega" are one person is a guess, and a guess here moves somebody's name up or down a list about risk. The cost is stated instead of hidden. One person under two spellings counts as two, which makes a bus factor read higher than it is, so when two names commit from the same address the report says which names, and leaves them apart.
No field of a Report holds an email address. The address is read only to make that one comparison and is dropped with the commit.
What distorts it ¶
A shallow clone has no history before the depth it was cloned at. A squash-merge workflow records a whole branch as one commit under one name, whoever wrote the commits inside it. A mass move or reformat credits whoever ran it in every directory it touched. All three are stated in every report, because a reader who does not know them reads a wrong number as a fact.
Bounds ¶
History is read through a commit limit, never unbounded. Directories with fewer than MinCommits commits are not measured, since one author out of two commits is not a finding, and the report counts them.
Index ¶
Constants ¶
const ( DefaultLimit = 20 DefaultCommitWindow = 5000 DefaultMonths = 12 DefaultMinCommits = 5 )
const Root = "."
Root is the path of the repository's top directory in a report.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Area ¶
type Area struct {
// Path is the directory or file, "." for the top directory.
Path string `json:"path"`
// BusFactor is the smallest number of names whose commits make up at least
// half of Commits.
BusFactor int `json:"bus_factor"`
// Commits is how many commits in the window touched the area.
Commits int `json:"commits"`
// Contributors is how many distinct author names those commits carry.
Contributors int `json:"contributors"`
TopShare float64 `json:"top_share"`
// TopLastChanged is when the largest contributor last changed the area.
TopLastChanged int64 `json:"top_last_changed_unix,omitempty"`
// TopIdleDays is how many days before the newest commit read that was. It
// is measured against the history, not the clock, so the same history
// gives the same number on any day.
TopIdleDays int `json:"top_idle_days"`
// LastChanged is when anybody last changed the area.
LastChanged int64 `json:"last_changed_unix,omitempty"`
// Top lists the largest contributors, largest first.
Top []Contributor `json:"top_contributors"`
}
Area is one measured directory or file.
type Commit ¶
type Commit struct {
SHA string
// Author is the author name as the history spells it.
Author string
// AuthorEmail is used only to notice two names committing from one
// address. It is never copied into a Report.
AuthorEmail string
When int64 // author time, Unix seconds
Paths []string
// ShallowBoundary marks a commit at the edge of a shallow clone; see
// ownership.Commit.ShallowBoundary.
ShallowBoundary bool
// Truncated marks the last commit of a walk cut by its time budget; see
// ownership.Commit.Truncated.
Truncated bool
}
Commit is one commit reduced to what the figure needs. Paths must already be in the index's path space; see internal/capability/ownership.Commit, whose reasoning for restating the type at the consumer applies here unchanged.
type Contributor ¶
type Contributor struct {
// Name is the author name as the history spells it.
Name string `json:"name"`
// Commits is how many commits under this name touched the area.
Commits int `json:"commits"`
Share float64 `json:"share"`
// LastChanged is the author time of the newest of them.
LastChanged int64 `json:"last_changed_unix,omitempty"`
}
Contributor is one author name's part in an area.
type History ¶
History is the bounded commit source. An implementation that cannot honour limit must return an error rather than read everything.
type Index ¶
Index tells the analysis which paths still exist, so a directory deleted since the commits that touched it is not reported as a risk.
type Options ¶
type Options struct {
// Limit is the most areas to return. Zero means DefaultLimit.
Limit int
// CommitWindow is how many recent commits to read. Zero means
// DefaultCommitWindow.
CommitWindow int
// Months is the time window: commits older than this many months before
// the newest commit read are left out. Zero means DefaultMonths; negative
// means no time bound, only CommitWindow. CommitWindow caps the walk
// either way, so on a busy repository the period read can be shorter than
// asked, and the report says so (PeriodCovered).
Months int
// MinCommits is the fewest commits an area needs to be measured. Zero
// means DefaultMinCommits.
MinCommits int
// PathPrefix restricts the analysis to files under it.
PathPrefix string
// Depth groups by the first Depth path segments instead of by each file's
// own directory. Zero means each file's own directory.
Depth int
// PerFile measures each file instead of each directory.
PerFile bool
// ShallowClone says the repository was cloned with truncated history,
// whether or not this walk reached the point where it was cut. A walk that
// does reach it says so itself (Commit.ShallowBoundary), so this is only
// needed for the other case: a window smaller than the clone depth, whose
// figures still leave out everyone older than the depth.
ShallowClone bool
}
Options bounds an analysis.
type Report ¶
type Report struct {
RunID int64 `json:"run_id"`
Unit Unit `json:"unit"`
// Areas are the measured areas, most at risk first, cut to the limit.
Areas []Area `json:"areas"`
// Measured is how many areas had enough commits to measure, before the
// limit. SolePerson is how many of those have a bus factor of one.
Measured int `json:"areas_measured"`
SolePerson int `json:"areas_with_bus_factor_one"`
// Excluded is how many areas the window touched but that had fewer than
// MinCommits commits. They are not low risk; they are unmeasured.
Excluded int `json:"areas_excluded_too_few_commits"`
MinCommits int `json:"min_commits"`
// NotIndexed is how many areas the window touched that the index no
// longer holds: deleted, renamed or ignored since.
NotIndexed int `json:"areas_not_indexed"`
// Overall is the same figure for every commit read that changed a file
// in scope, taken as one area. Its Path is the path prefix asked for,
// empty when there was none. Nil when no commit changed anything in scope.
Overall *Area `json:"overall,omitempty"`
// CommitsRead is how much history the figures are drawn from, and
// WindowFull says whether more history exists beyond it.
CommitsRead int `json:"commits_read"`
CommitWindow int `json:"commit_window"`
WindowFull bool `json:"window_full"`
OldestCommit int64 `json:"oldest_commit_unix,omitempty"`
NewestCommit int64 `json:"newest_commit_unix,omitempty"`
ShallowClone bool `json:"shallow_clone"`
// Months is the time window and SinceUnix where it starts (Months before
// NewestCommit). PeriodCovered says the whole period was read: the walk
// reached a commit older than SinceUnix, or the start of history.
Months int `json:"months,omitempty"`
SinceUnix int64 `json:"since_unix,omitempty"`
PeriodCovered bool `json:"period_covered"`
// Partial says the walk stopped at its time budget before reading the
// whole window; see ownership.Window.Partial.
Partial bool `json:"partial,omitempty"`
// SharedAddress lists groups of author names that committed from one
// address: possibly one person counted more than once. Names only.
// NamesCut is how many author names were recorded as an email address
// and are shown only up to the @.
NamesCut int `json:"names_recorded_as_addresses"`
// Notes say what this run could not see. Caveats say what the figure
// cannot establish on any run. Both are part of the answer.
Notes []string `json:"notes,omitempty"`
Caveats []string `json:"caveats"`
// contains filtered or unexported fields
}
Report is the answer to "where is knowledge held by too few people?".