Documentation
¶
Overview ¶
Package peers is the read-only peer reader (itd-2609091416295622, spc-2609202056480020): given one checkout, which records do the other checkouts and branches sharing its git common dir hold that this tree does not, or hold in a different state?
Every collision on record between two sessions on one machine was a failure of visibility: the peer's record sat on the same disk, and the verb that collided answered "not found". This package makes the holding visible and changes nothing. It opens no file for writing, runs only read-only git commands under gitutil's isolated environment, takes no lock, and stamps nothing — the claim, the lease and the register are other records' work.
A PEER is one of two things, read through one reader:
- a linked worktree git lists for this repository (`git worktree list`), confirmed from its own `--git-common-dir` and read off its disk, so an uncommitted capture in it is seen;
- a local branch no worktree has checked out, read from the common dir with `git ls-tree`, so a paused branch is seen with no checkout at all.
A third source, the register (itd-2609150819440345), is where holdings live across accounts and machines. Its slot is the Sources list: this package ships with the two local sources only, and says so in every Report.
A holding is an id by FILENAME, under the issue ledger's status folders and the intent store's buckets, read by the same filename grammar the record resolver reads (recordid.FilenameNumRe). A record file is opened only for its title, through the guarded read (fsutil.ReadGuarded: no symlink followed, no device blocked on, a size cap), and a title that cannot be read leaves the id with no title rather than failing the listing.
This package is a library: it returns values and errors, and never prints.
Index ¶
- Constants
- Variables
- func RecordsAt(root, ref string) (map[string][]RecordAt, error)
- type Kind
- type Location
- type Peer
- type RecordAt
- type Report
- func (r Report) HeldHere(id string) bool
- func (r Report) HeldUnder(dir string) (held, spent int)
- func (r Report) Holders(id, folder string) []Location
- func (r Report) IDCount() int
- func (r Report) Live() int
- func (r Report) Locate(id string) []Location
- func (r Report) Unjudged() []Peer
- func (r Report) Worktrees() []SeenWorktree
- type Row
- type SeenWorktree
- type Skipped
- type Source
Constants ¶
const ( SkipGone = "gone" SkipMerged = "merged" SkipEmbargo = "embargo store" )
Skip reasons: a spent peer contributes no rows and is counted instead. SkipEmbargo is the embargo store, which is not spent but private: its records are private security advisories' (adr-2610120558328615), so it is skipped unread and counted with no path.
const ( NotReadGitRefused = "git refused to answer for it: " NotReadSplit = "its ledger holds one id in two places" )
The starts of the not-read reasons a caller tells apart to choose a peer's repair: git would not answer for a worktree (most often a git file that points nowhere), and a ledger holds one id in two folders.
Variables ¶
var Sources = []Source{SourceWorktree, SourceBranch}
Sources is the set of sources this build reads. The register's slot is deliberately absent: a consumer reading a Report can tell "no peer holds it anywhere" from "no LOCAL peer holds it", which is all this build can say.
Functions ¶
func RecordsAt ¶ added in v0.15.1
RecordsAt is the record ids ref's tree holds, each with every file that claims it (its folder: open, resolved, wontfix, or an intent bucket; and its blob), read from the object store by filename, with no checkout and no network. It is the peers reader's own tree read, exported so a reservation decides which folder a record is in, and which blob it is, by the same reader.
Types ¶
type Kind ¶
type Kind string
Kind is which of the three diffs a row belongs to.
const ( // KindOpenThere is a record open in the peer and absent from every status // folder here: the peer captured something this tree has not seen. KindOpenThere Kind = "open-there" // KindTerminalThere is a record open here and resolved or won't-fixed in the // peer: the peer closed something this tree still thinks is open. KindTerminalThere Kind = "terminal-there" // KindDraftThere is an intent drafted in the peer and absent from every // bucket here. KindDraftThere Kind = "draft-there" )
type Location ¶
type Location struct {
Source Source `json:"source"`
Branch string `json:"branch,omitempty"`
Path string `json:"path,omitempty"`
Folder string `json:"folder"`
// contains filtered or unexported fields
}
Location is where a live peer holds one record.
type Peer ¶
type Peer struct {
Source Source `json:"source"`
// Branch is the peer's short branch name; empty for a detached worktree.
Branch string `json:"branch,omitempty"`
// Path is the worktree's absolute path as git reports it; empty for a
// branch peer. A surface redacts it before it reaches a stream.
Path string `json:"path,omitempty"`
// NotRead is set, with the reason, when the peer was named and not read:
// git refused to answer for it, its common dir is not this checkout's, its
// ledger holds one id twice, or it holds no ledger at the committed layout.
// A peer that was not read carries no rows.
NotRead string `json:"not_read,omitempty"`
Rows []Row `json:"rows"`
// contains filtered or unexported fields
}
Peer is one live peer and what it holds.
func (Peer) NotReadShown ¶ added in v0.15.1
NotReadShown is p's not-read reason as a surface prints it, with no absolute local path in it: the peer's own directory as fsutil.DisplayPathsIn names it, HOME as ~, the checkout at repoRoot as ., and any other absolute path, such as where a broken git file points, by its last element alone (iss-2609281329007423). Every surface that prints a reason prints this form: the drain's refusal, the build's peers check and `abcd peers`.
type RecordAt ¶ added in v0.15.1
RecordAt is one file a ref's tree holds a record in: its folder and the object name of its blob.
type Report ¶
type Report struct {
// Sources is the set of sources read (see Sources).
Sources []Source `json:"sources"`
// DefaultRef is the ref a branch is judged merged into, empty when none
// could be resolved (then nothing is skipped as merged).
DefaultRef string `json:"default_ref,omitempty"`
Peers []Peer `json:"peers"`
Skipped []Skipped `json:"skipped"`
// contains filtered or unexported fields
}
Report is the whole picture for one checkout.
func Read ¶
Read returns the peer picture for the checkout at root, which is a checkout root (gitutil.CheckoutRoot's answer), not an arbitrary directory under it.
It fails only when this checkout itself cannot be read: git will not name its common dir, or its own record folders cannot be listed. Every fault in a PEER is that peer's NotRead, so one bad sibling never hides the others.
func Scan ¶
Scan is Read without the titles: the same peers, rows and locations, with no record file opened. It is for a caller that needs counts or a location — the board line, a not-found refusal — and should not pay a read per row.
func (Report) HeldHere ¶
HeldHere reports whether this checkout holds id in any folder of its family.
func (Report) HeldUnder ¶ added in v0.16.0
HeldUnder counts the linked worktrees the scan saw whose real path lies beneath dir, and the spent ones among them: the board's worktrees line, with dir the repository's lane in the worktree store. A gone worktree is not counted, because it no longer occupies dir. Paths compare resolved, so a lane reached through a symlinked home still holds what git reports.
func (Report) Holders ¶ added in v0.16.0
Holders returns the live, read peers that hold id themselves, as against this checkout holding it in folder: those holding it in another folder of its family (a lane that shipped or re-drafted it) whose copy differs from the one in its merge-base with this checkout's HEAD. A copy in folder is a copy, not a holding: every branch cut from the default branch carries one. So is a copy identical, at the same path, to the one in every merge-base tree of the peer and this checkout: the peer was cut before the record moved here and holds this checkout's older copy, which it never touched (iss-2610222008081888). It is measured against this checkout, not the default branch, so a peer cut after the default branch shipped what this checkout, being behind, still holds as planned holds it shipped. In a criss-cross history every merge-base must agree. A worktree peer is judged off its disk, against the merge-bases of its HEAD, so an uncommitted move or edit is a change.
It fails closed: where this checkout's HEAD (unborn, or unreadable), the merge-bases, a merge-base tree's entry or the peer's copy cannot be read, the location holds it. The comparison is made only for a location in another folder, and the merge-bases once per peer for the Report's life.
Locate keeps every location: a not-found path asks where a record is, and a stale copy is still where it is.
func (Report) Locate ¶
Locate returns every live, read peer that holds id, in any folder of its family. It is the not-found paths' question: a verb that cannot find a record here asks where it is before answering "not found".
func (Report) Unjudged ¶ added in v0.11.1
Unjudged returns the live peers that were named and not read for a reason that leaves what they hold unknown: git or the filesystem would not answer for them, or their ledger holds one id in two folders. Locate cannot see into these, so a caller that must not start past a peer's holding treats each as one. A peer of another repository, and one holding no records at the committed layout, hold nothing of this checkout's and are not returned.
func (Report) Worktrees ¶ added in v0.16.0
func (r Report) Worktrees() []SeenWorktree
Worktrees lists every linked worktree the scan saw, sorted by path: each worktree peer, read or not, and each worktree skipped as merged or gone. The main checkout is not one, and neither is the embargo store, which is skipped unnamed. It reads nothing; a caller counting worktrees (the board's store line) takes them from the scan it already ran.
type Row ¶
type Row struct {
ID string `json:"id"`
Kind Kind `json:"kind"`
// Folder is the folder that holds the record in the PEER: open, resolved,
// wontfix or drafts.
Folder string `json:"folder"`
// Title is the record's title, empty when the file could not be read or is
// malformed; the id is listed either way.
Title string `json:"title,omitempty"`
}
Row is one record a peer holds that this tree does not, or holds in another state.
type SeenWorktree ¶ added in v0.16.0
type SeenWorktree struct {
Path string `json:"path"`
Branch string `json:"branch,omitempty"`
// Spent is the scan's merged judgement: its branch (or detached HEAD) is
// merged into the default branch by ancestry and its record folders are
// clean (SkipMerged).
Spent bool `json:"spent,omitempty"`
// Gone is a worktree git lists whose directory is not there (SkipGone).
Gone bool `json:"gone,omitempty"`
}
SeenWorktree is one linked worktree a scan saw: its path as git reports it, its short branch ("" when detached), and how the scan judged it.
type Skipped ¶
type Skipped struct {
Source Source `json:"source"`
Branch string `json:"branch,omitempty"`
Path string `json:"path,omitempty"`
Reason string `json:"reason"`
}
Skipped is a spent peer: its worktree directory is gone, or its branch is merged into the default branch (and, for a worktree, its record folders hold no uncommitted change).
type Source ¶
type Source string
Source names where a peer was read from.
const ( // SourceWorktree is a linked worktree sharing this checkout's common dir, // read off its disk. SourceWorktree Source = "worktree" // SourceBranch is a local branch no worktree has checked out, read from // the common dir. SourceBranch Source = "branch" // SourceRegister is the slot the register intent (itd-2609150819440345) // fills: holdings across accounts and machines. Nothing reads it yet. SourceRegister Source = "register" )