Documentation
¶
Overview ¶
Package stack is how a task branch stands on its base: the branch index, the After: base, base code checks, the catchup engine and verify runs.
Index ¶
- Constants
- Variables
- func BaseHasCode(ctx context.Context, main, branch, def string) bool
- func BodyAfter(ctx context.Context, tr Tracker, main string, task ref.Ref, body string) (string, string, error)
- func BranchDiff(ctx context.Context, dir, main string) (string, []string, error)
- func BranchName(ctx context.Context, d *driver.Driver, task ref.Ref, suffix string, ...) (string, string, error)
- func BranchUnsettled(ctx context.Context, main, dir, branch string) string
- func BundleAfter(ctx context.Context, tr Tracker, task ref.Ref, body string) (string, error)
- func CatchupConflict(ctx context.Context, main, dir, branch string, key branchmeta.Key) (string, string, error)
- func CatchupRecord(ctx context.Context, main, dir, branch string, key branchmeta.Key, ...) (*drives.Catchup, error)
- func ChangeTrailer(task, change string) string
- func ChildRefs(rows []ChildRow) []ledger.TaskRef
- func ClearMarks(ctx context.Context, main, branch string, p CatchupPlan) error
- func ConflictFingerprint(ctx context.Context, dir, target string) (string, string, error)
- func DefaultBranch(ctx context.Context, dir string) string
- func DefaultTargetOf(ctx context.Context, main, def string) (string, string, error)
- func DefaultTip(ctx context.Context, dir, def string, policy tipPolicy) (string, string, error)
- func FinishedTask(info hostops.TaskInfo, root storage.Root, id string, hasBranch bool) bool
- func ForkPoint(ctx context.Context, dir, head, base string) (string, error)
- func HasTaskBranch(ctx context.Context, dir, id string) (bool, error)
- func IntegrateWith(resolve func(context.Context, CatchupInput) (CatchupPlan, error)) ...
- func LinkAfter(body, link string) string
- func ListOrNone(paths []string) string
- func LocalDefault(ctx context.Context, dir string) (string, error)
- func MarkOn(ctx context.Context, main, branch string) (branchmeta.Key, error)
- func NamedRef(ctx context.Context, dir, branch string) (string, string, error)
- func NewerMergeBase(ctx context.Context, dir, head, base string) (string, error)
- func OpenSubtasks(ctx context.Context, tr Tracker, r ref.Ref) ([]string, error)
- func OriginBaseHasCode(ctx context.Context, main, branch, def string) bool
- func PRBase(ctx context.Context, warn io.Writer, main, branch string) (string, error)
- func PushCatchup(ctx context.Context, dir, branch string, rec *drives.Catchup) (string, error)
- func RawChildrenFor(ctx context.Context, t *target.Target, task ref.Ref) ([]hostops.RawChild, error)
- func ReadTarget(ctx context.Context, main string, t PRTarget, prBase, local, origin string) (targetState, error)
- func RecordTip(ctx context.Context, dir, branch, base string) error
- func RecordedBase(ctx context.Context, main, branch string) (string, string, error)
- func RefSHA(ctx context.Context, dir, r string) string
- func RememberRefsFor(ctx context.Context, t *target.Target, refs ...ledger.TaskRef)
- func RiderRefs(root, id string) []string
- func Slugify(title string) string
- func TaskCheckout(ctx context.Context, main string, d *driver.Driver, task ref.Ref, ...) (string, string, error)
- func TaskRefs(root, id string) []string
- func TaskRows(ctx context.Context, t *target.Target, limit int) ([]hostops.Row, error)
- func TreeBusy(ctx context.Context, dir string) string
- func WorktreeOf(wts []gitx.Worktree, branch string) string
- type BranchIndex
- func (x *BranchIndex) After(ctx context.Context, id string) (string, error)
- func (x *BranchIndex) Any(ctx context.Context, id string) (string, error)
- func (x *BranchIndex) Bundle(branch, prefix string) (string, []string)
- func (x *BranchIndex) Find(ctx context.Context, want, id, suffix string, roots BranchPolicy) (FoundBranch, error)
- func (x *BranchIndex) Linked(id string) []string
- func (x *BranchIndex) Record(branch string) branchmeta.Record
- func (x *BranchIndex) Under(ctx context.Context, root, id, suffix string) ([]string, error)
- type BranchPolicy
- type CatchupEngine
- func (e *CatchupEngine) CleanSteering(base string) string
- func (e *CatchupEngine) ConflictSteering(p CatchupPlan, branch, who string, paths []string) string
- func (e *CatchupEngine) Input(main, dir string) CatchupInput
- func (e *CatchupEngine) Left(ctx context.Context, main, dir, branch string, p CatchupPlan) (TreeState, error)
- func (e *CatchupEngine) Message(tasks []string, change string) func(CatchupPlan) []string
- func (e *CatchupEngine) VerifyClause() string
- type CatchupInput
- type CatchupPlan
- type ChildRow
- type FetchOnce
- type FoundBranch
- type OriginMovedError
- type PRTarget
- type Tracker
- type TreeState
- type VerifyRun
- type VerifySpec
Constants ¶
const ( FoundLanded = string(branchmeta.Landed) FoundAfter = string(branchmeta.AfterBranch) FoundGone = string(branchmeta.AfterBranch) + " gone" FoundDefault = "default branch" )
What a base was found through, in the step's words.
const ( CodeYes = "yes" CodeNone = "none" )
The code row's values.
const ( MethodMerge = "merge" MethodRebase = "rebase" MethodOnto = "onto" MethodNone = "none" MethodSkip = "skip" )
Methods besides merge and rebase: none has nothing to bring in, skip is a guard with nothing to do.
const ( // DivergeFail refuses: a local landing would fold one side's commits into the other. DivergeFail tipPolicy = iota )
const SlugMax = 40
SlugMax is where a slug is cut: long enough to carry a title's meaning, short enough for a tab label and a worktree path.
Variables ¶
var ( VerifyLimit = 30 * time.Minute VerifyWaitDelay = 5 * time.Second )
VerifyLimit bounds one verify command the drive runs itself, and VerifyWaitDelay how long its output is read once it was killed.
var ErrBaseNotPushed = errors.New("its base is not on origin yet")
ErrBaseNotPushed is a push held back because the base the catchup brought in is not on origin yet: the push would carry its commits into the PR.
var ErrOpUnread = errors.New("could not tell whether a merge or rebase is in progress")
ErrOpUnread is a read of a worktree that could not tell whether a merge or rebase is in progress there.
var PolicyLocal = BranchPolicy{"refs/heads/"}
PolicyLocal never tracks origin's copy, as a landed pickup must not
var PolicyLocalOrOrigin = BranchPolicy{"refs/heads/", "refs/remotes/origin/"}
Functions ¶
func BaseHasCode ¶
BaseHasCode reports a non-merge commit on a base task's branch past the default branch, its own recorded base and its creation commit: a merge is a catchup's, never code. The drive and ship's guard both decide by it, on local refs, so a branch never pushed counts.
func BodyAfter ¶
func BodyAfter(ctx context.Context, tr Tracker, main string, task ref.Ref, body string) (string, string, error)
BodyAfter is the base the body's After: line gives start when no flag names one. A base with a branch is the dependency, a finished one is in the default branch already; anything else is refused before anything is made.
func BranchDiff ¶
BranchDiff is VerifyDiff for the checkout at dir, main the main checkout.
func BranchName ¶
func BranchName( ctx context.Context, d *driver.Driver, task ref.Ref, suffix string, title func(context.Context) (string, error), ) (string, string, error)
BranchName is the task's branch name and, when no slug came, the note saying why.
func BranchUnsettled ¶
BranchUnsettled says why a catchup did not bring branch up to date, or "". Read from git, since catchup clears the mark only once verify is green.
func BundleAfter ¶
BundleAfter is the After: line a task answers to: its body's, or for a bundle the one base its members name outside the bundle. A line naming another member orders work inside the branch; two bases cannot both be it.
func CatchupConflict ¶
func CatchupConflict(ctx context.Context, main, dir, branch string, key branchmeta.Key) (string, string, error)
CatchupConflict is the fingerprint of the conflict branch meets with a mark's target now, and the files it conflicts on.
func CatchupRecord ¶
func CatchupRecord( ctx context.Context, main, dir, branch string, key branchmeta.Key, now time.Time, fetched *FetchOnce, ) (*drives.Catchup, error)
CatchupRecord notes what the catchup about to go out for a mark starts from. A read git cannot answer fails: a record made up would halt a healthy task, or loop on a doomed one.
func ChangeTrailer ¶
ChangeTrailer names a later series' lore change, since a squash drops the branch's own trailers and Task: alone leads lore why to the first PR.
func ClearMarks ¶
func ClearMarks(ctx context.Context, main, branch string, p CatchupPlan) error
ClearMarks unsets the catchup marks once the base is in and verify is green, and records the base the branch now stands on, as the step does.
func ConflictFingerprint ¶
ConflictFingerprint is the fingerprint of the conflict the worktree at dir meets merging target, and the files it conflicts on; the drive and the watcher compare these, so both build them here.
func DefaultBranch ¶
DefaultBranch is what origin points HEAD at (`origin/main`), or "" to let git use the current HEAD - the same default worktrunk applies.
func DefaultTargetOf ¶
func DefaultTip ¶
DefaultTip is the default branch's tip to work from, and its name (def or origin/<def>). One side missing gives the other; otherwise a side that holds the other wins, and divergence goes by policy.
func FinishedTask ¶
FinishedTask is the one "is this task done with": no branch, no live plan (a re-plan is pending work whatever the tracker says), and closed or its plan archived, which catches a merge whose PR body closed no issue.
func ForkPoint ¶
ForkPoint is where the subject's branch left its base: the newer of the merge bases with the local and origin copies, so neither unpushed commits of the base nor origin moving ahead read as this change.
func HasTaskBranch ¶
HasTaskBranch reports a branch of the task, linked, local or on origin.
func IntegrateWith ¶
func IntegrateWith( resolve func(context.Context, CatchupInput) (CatchupPlan, error), ) func(context.Context, CatchupInput, func(CatchupPlan) []string) (CatchupPlan, bool, error)
IntegrateWith is IntegrateBranch deciding the base with resolve, which a test scripts. A failed fetch decides on the refs at hand, as the step does: an integration needs some base, where originTip needs origin's real tip.
func ListOrNone ¶
func LocalDefault ¶
LocalDefault is the default branch as a local name. Without it finish cannot tell a stacked PR from one against main, nor what to pull.
func NamedRef ¶
NamedRef is the ref --base names, with its commit. Exact refs rather than for-each-ref, since a base is one commit and a literal pattern would also match everything below the name at a slash.
func NewerMergeBase ¶
NewerMergeBase is the newer of head's merge bases with base's local and origin copies, "" with neither. Two that diverged give origin's, the copy a request is compared against and a guard integrates.
func OpenSubtasks ¶
OpenSubtasks is the check start and drive make before a task runs as one of its own.
func OriginBaseHasCode ¶
OriginBaseHasCode is BaseHasCode for a base only origin holds: with no reflog there is no creation commit, so the base's own base is read on origin too.
func PRBase ¶
PRBase is the branch the subject's request targets or would target. A recorded base found nowhere was finished and deleted, so its code is on the default branch; that is said on warn. PRTargetOf keeps "found nowhere" as its own answer, which drive and the watcher wait on.
func PushCatchup ¶
PushCatchup is the one push after a clean catchup of a branch origin has: plain when it fast-forwards origin, leased against rec's origin tip after a rewrite, and never carrying a base origin lacks. A rewrite with no live lease is refused as unseen; a push or a refusal spends the lease.
func RawChildrenFor ¶
func RawChildrenFor(ctx context.Context, t *target.Target, task ref.Ref) ([]hostops.RawChild, error)
RawChildrenFor is the task's subtasks as the tracker holds them; ErrNoParentLink when it has no parent link to read.
func ReadTarget ¶
func ReadTarget(ctx context.Context, main string, t PRTarget, prBase, local, origin string) (targetState, error)
ReadTarget reads t against the PR's base and the branch's local and origin tips; a prBase of "" skips the retarget check.
func RecordTip ¶
RecordTip records the base commit branch is built on, so a catchup after the base's history is rewritten replays only branch's own commits. The newer of the local and origin merge-bases wins: a guard integrates origin's copy, which a stale local branch would hide. A base found nowhere keeps the tip recorded before.
func RecordedBase ¶
RecordedBase is the f10-after-branch base start recorded on branch, and its sha, origin's copy first; sha is "" for a base found nowhere.
func RememberRefsFor ¶
RememberRefsFor records refs as this project's; it never fails its caller.
func RiderRefs ¶
RiderRefs are the patterns of a bundle branch the id rides in, past its lead: `<lead>+<id>`, `<lead>+<id>+<more>`, each bare or slugged.
func Slugify ¶
Slugify cuts at the last hyphen at or before SlugMax so no word is split, hard at SlugMax when there is none.
func TaskCheckout ¶
func TaskCheckout( ctx context.Context, main string, d *driver.Driver, task ref.Ref, suffix string, ) (string, string, error)
TaskCheckout is the task's branch and the checkout that has it checked out: both "" with no local branch, the path "" when checked out nowhere. No title lookup: a slug would cost a host call for nothing.
func TaskRefs ¶
TaskRefs are the patterns a task's branch can sit under a root. for-each-ref extends a bare id to everything below it at a slash, but a `*` stops at a slash, so a slugged bundle needs its own pattern.
Types ¶
type BranchIndex ¶
type BranchIndex struct {
// contains filtered or unexported fields
}
A BranchIndex answers which branch is a task's, from every branch's record read once. Build one per command and never keep it across a write to the records, since it answers from the read.
func LoadBranchIndex ¶
func LoadBranchIndex(ctx context.Context, dir string) (*BranchIndex, error)
func (*BranchIndex) After ¶
After is the branch --after names. Nothing or several matching fails before anything is created, since guessing would base the work on the wrong attempt.
func (*BranchIndex) Any ¶
Any is the first branch of the task, linked, local or origin's (`origin/<name>`), or "" for none.
func (*BranchIndex) Bundle ¶
func (x *BranchIndex) Bundle(branch, prefix string) (string, []string)
Bundle is the lead and riders a branch ships: its recorded riders, led by its link else the id its name carries, then the ids its name spells, as a fetched branch carries them.
func (*BranchIndex) Find ¶
func (x *BranchIndex) Find(ctx context.Context, want, id, suffix string, roots BranchPolicy) (FoundBranch, error)
Find is the branch to reuse, or none when the task has none yet. Several is an error, since a suffix exists to say which; a suffix skips the link, naming an attempt by its branch name.
func (*BranchIndex) Linked ¶
func (x *BranchIndex) Linked(id string) []string
Linked are the local branches linked to id as lead or rider: a picked-up PR's branch need not carry the id, and a bundle's branch is found by any member.
func (*BranchIndex) Record ¶
func (x *BranchIndex) Record(branch string) branchmeta.Record
type BranchPolicy ¶
type BranchPolicy []string
A BranchPolicy is where find looks past the link: the roots it searches, in order.
type CatchupEngine ¶
type CatchupEngine struct {
// Policy holds the catchup keys; dir, main and ShipStopped are set per task
Policy CatchupInput
// AgentVerifies says why the agent runs verify after a clean integration
// and clears the marks once green, "" when the binary runs verify
AgentVerifies string
// Integrate, verify and base are the git and the verify the engine
// runs, replaced by tests that script neither; base reads the base the
// marks name without a fetch
Integrate func(ctx context.Context, in CatchupInput, message func(CatchupPlan) []string) (CatchupPlan, bool, error)
Verify func(ctx context.Context, dir, log string) (VerifyRun, error)
Base func(ctx context.Context, in CatchupInput) (CatchupPlan, error)
// contains filtered or unexported fields
}
CatchupEngine is how a branch is caught up from outside its agent.
func NewCatchupEngine ¶
func NewCatchupEngine(policy CatchupInput, spec VerifySpec, why string, traces bool, main string) *CatchupEngine
NewCatchupEngine is the real git and verify; why, when not "", is the reason spec cannot run and the agent verifies instead.
func (*CatchupEngine) CleanSteering ¶
func (e *CatchupEngine) CleanSteering(base string) string
CleanSteering is the turn the agent gets after a clean integration when the binary cannot run verify.
func (*CatchupEngine) ConflictSteering ¶
func (e *CatchupEngine) ConflictSteering(p CatchupPlan, branch, who string, paths []string) string
ConflictSteering is what a turn settles after git stopped on conflicts.
func (*CatchupEngine) Input ¶
func (e *CatchupEngine) Input(main, dir string) CatchupInput
Input is the policy for one worktree.
func (*CatchupEngine) Left ¶
func (e *CatchupEngine) Left(ctx context.Context, main, dir, branch string, p CatchupPlan) (TreeState, error)
Left reads what keeps the branch from being caught up with p (TreeState's left), and when the agent verifies, whether a mark is still set.
func (*CatchupEngine) Message ¶
func (e *CatchupEngine) Message(tasks []string, change string) func(CatchupPlan) []string
Message is a catchup merge's message: git's own subject, then the trailers a catchup commit carries for tasks, change naming its PR series.
func (*CatchupEngine) VerifyClause ¶
func (e *CatchupEngine) VerifyClause() string
VerifyClause tells a turn under an agent-run verify to verify and clear the marks itself; under the binary's verify it adds nothing.
type CatchupInput ¶
type CatchupInput struct {
Dir, Main string
Guard string // "" for a run asked for by name, else the entry it guards
Catchup, Stacked string
CatchupDefault, StackedDefault bool // the value is the default, not declared
ShipStopped bool
// Fetched is the tick's or the watcher pass's fetch, nil outside one
Fetched *FetchOnce
}
func CatchupPolicy ¶
func CatchupPolicy(eff *facts.Effective) CatchupInput
CatchupPolicy is the catchup keys of the effective configuration.
type CatchupPlan ¶
type CatchupPlan struct {
Branch, Base, SHA, Found, How, Method, Why, Mark string
// Upstream is the base's old tip that onto rebases from
Upstream string
// Code says whether a recorded base branch has commits of its own: ship
// waits on one with none, by the rule the drive releases dependents on
Code string
}
func IntegrateBranch ¶
func IntegrateBranch( ctx context.Context, in CatchupInput, message func(CatchupPlan) []string, ) (CatchupPlan, bool, error)
IntegrateBranch decides the base and method as f10 pr catchup does and integrates; stopped is a conflict left in progress.
func ResolveCatchup ¶
func ResolveCatchup(ctx context.Context, in CatchupInput) (CatchupPlan, error)
type ChildRow ¶
type ChildRow struct {
ID string `json:"id"`
Title string `json:"title"`
URL string `json:"url,omitempty"`
State string `json:"state,omitempty"`
Labels []string `json:"labels"`
After string `json:"after,omitempty"`
Finished bool `json:"finished"`
Depth int `json:"depth"`
Number int `json:"-"`
Suffix string `json:"-"` // a launched start's worktree suffix: the checkout read is that one
Queued bool `json:"-"` // a drive's cap holds it back
Phase string `json:"-"` // where its drive's record says it stands, a drives.Phase name
}
A ChildRow is one open subtask. Rows come in tree order: a child whose After: base is a sibling follows that sibling one level deeper.
type FetchOnce ¶
type FetchOnce struct{ Done bool }
A FetchOnce fetches origin at most once, a tick's or a watcher pass's: every worktree shares the main checkout's remote refs, so one fetch serves them all. A failed fetch is not kept, so the next caller tries again. A nil one, a caller outside any tick, fetches every time.
type FoundBranch ¶
A FoundBranch is the branch find settled on, and whether only origin has it, in which case start creates the local branch tracking it.
type OriginMovedError ¶
type OriginMovedError struct {
Branch, Path string
Unseen bool
// contains filtered or unexported fields
}
OriginMovedError refuses a force-push that could drop commits pushed to the branch while its catchup ran: origin moved, or, unseen, nothing recorded what origin held when the catchup went out.
func (OriginMovedError) Error ¶
func (e OriginMovedError) Error() string
type PRTarget ¶
type PRTarget struct {
SHA, Name, Value string
Key branchmeta.Key
}
PRTarget is what a task's PR targets and the mark that sends a catchup for it: origin's copy of the f10-after-branch base, else its local copy, else the default branch. sha is "" for a base found nowhere.
type Tracker ¶
type Tracker struct {
Resolve func(ctx context.Context, token string) (ref.Ref, error)
Info func(ctx context.Context, task ref.Ref) (hostops.TaskInfo, error)
// Children is the task's open subtasks; nil, like ErrNoParentLink, is a
// tracker with no parent link
Children func(ctx context.Context, task ref.Ref) ([]ChildRow, error)
// AllChildren is children with the closed ones kept, for status
AllChildren func(ctx context.Context, task ref.Ref) ([]ChildRow, error)
Storage storage.Root // where a finished task's plan is archived
// contains filtered or unexported fields
}
A Tracker answers the questions start and drive ask of the task source. Funcs rather than a target, so the flows run under test without one.
func TrackerFor ¶
TrackerFor binds the lookups to this target: the driver's `read` for the body where the project has one, the host's issue otherwise.
type TreeState ¶
A TreeState is what git shows of a worktree a catchup acts on: an operation in progress and the uncommitted paths, and once WithBase ran, whether the branch holds the base and the conflict markers left past it.
type VerifyRun ¶
type VerifyRun struct {
Failed, Log string
}
A VerifyRun is verify run once: the first command that failed, with its output in log, or "" when every command passed.
type VerifySpec ¶
type VerifySpec struct {
List []facts.VerifyDecl
Cmds []string
}
A VerifySpec is the verify the drive can run without a model: the frontmatter list, scoped to the branch's diff, or a fixed set of commands.