peers

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 16 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 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

View Source
const (
	SkipGone   = "gone"
	SkipMerged = "merged"
)

Skip reasons: a spent peer contributes no rows and is counted instead.

Variables

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

This section is empty.

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"`
}

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.

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

func Read(root string) (Report, error)

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

func Scan(root string) (Report, error)

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

func (r Report) HeldHere(id string) bool

HeldHere reports whether this checkout holds id in any folder of its family.

func (Report) IDCount

func (r Report) IDCount() int

IDCount is the number of distinct record ids across every peer's rows.

func (Report) Live

func (r Report) Live() int

Live is the number of live peers: those read, and those named but not read.

func (Report) Locate

func (r Report) Locate(id string) []Location

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

func (r Report) Unjudged() []Peer

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.

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 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"
)

Jump to

Keyboard shortcuts

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