reservesweep

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 14 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 reservesweep deletes spent reservation branches from origin (iss-2610142200389875). A reservation (internal/core/claim) is a branch `refs/heads/abcd-reserved/<record-id>` that ends with a tombstone and is never deleted by the verb that wrote it, and the reservations ruleset forbids its deletion to everyone but the one automation the ruleset names as its bypass actor, so the branches pile up on the forge.

The sweep fetches the reservations and origin's default branch, judges each branch (judge), and with Apply deletes the spent ones, each with a compare-and-swap on the exact tip it judged, so a branch re-reserved meanwhile survives. Without Apply it deletes nothing and says what it would. It never writes to stdout: a front door renders its Report.

Index

Constants

View Source
const (
	// SpentTerminal: the record is resolved, won't-fixed, shipped or
	// superseded on origin's default branch, so internal/core/claim already
	// counts the reservation as released whatever its tip says.
	SpentTerminal = "terminal"
	// SpentReleased: the tip is a plain tombstone and no hand-back stands
	// anywhere on the branch.
	SpentReleased = "released"
	// SpentLapsed: the tip is a reservation whose lease lapsed, over a plain
	// tombstone, and no hand-back stands anywhere on the branch.
	SpentLapsed = "lapsed"
	// SpentUnreleased: every commit on the branch is a reservation and the
	// tip's lease lapsed, so any session may already take it over and the
	// branch protects nothing.
	SpentUnreleased = "lapsed_unreleased"
)

Why a branch is spent.

View Source
const (
	KeptUnreadable = "unreadable"
	KeptRecent     = "recent"
	KeptUnknown    = "unknown_kind"
	KeptHandBack   = "hand_back"
	KeptHistory    = "history_unread"
)

Why a branch is kept.

View Source
const (
	// Deleted: origin took the deletion.
	Deleted = "deleted"
	// Moved: the branch moved after it was judged, so the compare-and-swap
	// refused the deletion and the branch stands.
	Moved = "moved"
	// Failed: origin refused the deletion for another reason (the ruleset,
	// a hook, the network); Error says why.
	Failed = "failed"
)

Outcome of one deletion.

View Source
const DefaultAge = 7 * 24 * time.Hour

DefaultAge is how long a branch whose tip is not a release must have been untouched, past its lease, before the sweep counts it spent; a plain release, and a hand-back on a terminal record, wait for no age (judge).

View Source
const MinAge = 24 * time.Hour

MinAge is the shortest age a sweep takes: a day, the longest a lease holds (lease.Max), so no age the sweep accepts is shorter than a lease.

Variables

This section is empty.

Functions

func IsNoOrigin

func IsNoOrigin(err error) bool

IsNoOrigin reports whether err is the refusal of a checkout with no origin.

Types

type Branch

type Branch struct {
	Record string
	// Ref is the branch's full ref on origin.
	Ref    string
	Commit string
	// Kind is the tip's kind.
	Kind  Kind
	Spent bool
	// Reason is one of the Spent* or Kept* reasons.
	Reason string
	// Why says what made a commit unknown, or the tip unreadable.
	Why string
	// SettledAt is when the tip last held or was written; zero when the tip
	// could not be read.
	SettledAt time.Time
	// Outcome is the deletion's outcome under Apply; "" otherwise.
	Outcome string
	// Error is why a deletion failed.
	Error string
}

Branch is one reservation branch as the sweep judged it.

type Kind

type Kind string

Kind is what one commit on a reservation branch is, as the sweep reads it. Anything the sweep cannot classify is KindUnknown, and a branch carrying one is never spent: the sweep fails closed.

const (
	// KindUnknown is a commit the sweep cannot classify: an unparseable
	// object, a tree that is not the empty tree, a message the claim
	// package's reader refuses (a time that does not read, a hand-back kind
	// outside claim.HandBackKinds among them), or a subject or a trailer the
	// sweep does not know.
	KindUnknown Kind = "unknown"
	// KindReservation is a reservation, a renewal or a take-over: it carries
	// no release time.
	KindReservation Kind = "reservation"
	// KindPlainTombstone is a release that hands nothing back.
	KindPlainTombstone Kind = "plain_tombstone"
	// KindHandBack is a release that hands the record back to a person, so
	// other accounts' drains do not take it again.
	KindHandBack Kind = "hand_back"
)

type Options

type Options struct {
	// Now is the clock; nil means time.Now.
	Now func() time.Time
	// Age is how long a branch whose tip is not a release (judge) must have
	// been untouched; zero means DefaultAge. Shorter than MinAge is refused.
	Age time.Duration
	// Apply deletes the spent branches; without it nothing is deleted.
	Apply bool
}

Options carries what a caller may set about a sweep.

type Report

type Report struct {
	AsOf    time.Time
	Age     time.Duration
	Applied bool
	// DefaultUnread is why origin's default branch could not be read, so no
	// branch was judged spent by its record being finished there.
	DefaultUnread string
	Branches      []Branch
}

Report is one sweep.

func Sweep

func Sweep(root string, o Options) (Report, error)

Sweep fetches the reservations and origin's default branch, judges every reservation branch, and under Apply deletes the spent ones.

func (Report) Counts

func (r Report) Counts() (spent, kept, deleted int)

Counts are the report's totals: branches spent, kept and deleted.

func (Report) Failed

func (r Report) Failed() bool

Failed reports whether any deletion failed for a reason other than the branch having moved.

Jump to

Keyboard shortcuts

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