Documentation
¶
Overview ¶
Package retention decides which commits of a set a policy keeps.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Default = Policy{KeepLast: 1, Brackets: []Bracket{ {Period: Hourly, Count: 14 * 24}, {Period: Daily, Count: 60}, {Period: Weekly, Count: 12}, {Period: Monthly}, }}
Default is the policy a store applies until it sets its own.
var ErrInvalidPolicy = errors.New("invalid retention policy")
ErrInvalidPolicy wraps every validation failure.
KeepAll is a policy that retires nothing.
Functions ¶
This section is empty.
Types ¶
type Bracket ¶
A Bracket keeps the last commit of each of Count UTC calendar periods. Brackets run consecutively back from now, each starting with the period the one before it ended in. A Count of zero is the tail: every period older than the brackets before it, kept forever.
func ParseBracket ¶
ParseBracket reads a bracket as Bracket.String writes it.
type Decision ¶
Decision is the outcome for one commit: kept for the listed reasons, or retired.
func Evaluate ¶
Evaluate applies the policy to a set's commits and returns one decision per commit, in input order. The newest commit is always kept. A partial commit is kept only while it is the newest; it counts for no rule. A pinned commit is kept and counts like any other. Commits within KeepWithin of now are kept regardless of counts.
func (Decision) RetainedBy ¶
RetainedBy renders the reasons as the string stored on the commit row.
type Period ¶
type Period string
Period is how finely a bracket keeps: one commit per hour, day, week or month of the stretch it covers.
type Policy ¶
Policy is what a set keeps. Brackets divide its past into consecutive stretches, each kept at its own granularity; KeepLast and KeepWithin hold on to the newest commits regardless of which bracket they fall in. The rules are ORed, and KeepLast is never below 1.
func (Policy) MarshalJSON ¶
MarshalJSON writes keep_within as a duration string.
func (Policy) String ¶
String is the policy as the flags of goback set that set it: "keep-last=1 keep=daily=60 keep=monthly keep-within=24h0m0s".
func (*Policy) UnmarshalJSON ¶
UnmarshalJSON reads keep_within as a duration string. A policy written when periods were counted rather than bracketed is refused rather than read as the brackets it has none of, which would retire everything the counts were holding.
func (Policy) Validate ¶
Validate rejects a policy with a negative counter, a keep_last below 1 or nothing to keep at all.