Documentation
¶
Overview ¶
Package plan models what a preen run intends to do before anything moves. A plan is data: it can be rendered for approval, edited by the user, and validated against the working tree without touching the repository.
Index ¶
- Constants
- Variables
- type Action
- type ActionKind
- type Commit
- type Held
- type Hunk
- type Part
- type Plan
- func (p *Plan) DropPath(path string) error
- func (p *Plan) LeavePath(change Part) error
- func (p *Plan) MergeInto(from, into int) error
- func (p *Plan) MovePath(path string, to int) error
- func (p Plan) Render(w io.Writer) error
- func (p *Plan) Reorder(order []int) error
- func (p Plan) Resets() bool
- func (p Plan) Revalidate() error
- func (p *Plan) Reword(number int, subject string) error
- func (p *Plan) SplitByFile(number int) error
- func (p Plan) Validate(changes []repo.Change) error
Constants ¶
const EditHelp = `` /* 522-byte string literal not displayed */
EditHelp lists the commands the approval prompt understands.
Variables ¶
var ( // ErrInvalid reports a plan that does not account for the working tree // exactly once, or that holds an empty or unnamed commit. ErrInvalid = errors.New("invalid plan") // ErrNoSuchCommit reports an edit naming a commit number the plan lacks. ErrNoSuchCommit = errors.New("no such commit in the plan") // ErrNoSuchPath reports an edit naming a path the plan does not carry. ErrNoSuchPath = errors.New("no such path in the plan") // ErrUsage reports a command typed at the approval prompt that could not // be understood. ErrUsage = errors.New("cannot read that command") )
Sentinel errors for plan construction and editing.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
// Kind is what the command asks for.
Kind ActionKind
// Describe is a short account of the edit, echoed back after it applies.
Describe string
// Apply changes the plan. It is set only for ActionEdit.
Apply func(p *Plan) error
}
Action is one parsed command from the approval prompt.
func ParseAction ¶
ParseAction reads one command typed at the approval prompt.
The grammar matches how the moves read in English, so "merge 2 into 1" and "move api/server.go to 3" work as written, and the filler words are optional.
type ActionKind ¶
type ActionKind int
ActionKind is what a typed approval-prompt command asks for.
const ( // ActionEdit changes the plan and stays at the prompt. ActionEdit ActionKind = iota // ActionApply accepts the plan as shown. ActionApply // ActionAbort leaves without changing anything. ActionAbort // ActionShow redisplays the plan. ActionShow // ActionHelp lists the available commands. ActionHelp )
The actions available at the approval prompt.
type Commit ¶
type Commit struct {
// Subject is the first line of the message.
Subject string
// Body is the optional message body.
Body string
// Parts are the file contributions this commit takes, in listing order.
Parts []Part
}
Commit is one planned commit: a message and the parts it will contain.
type Held ¶
type Held struct {
// Part is the change being left uncommitted.
Part Part
// Pattern is the rule that matched the path.
Pattern string
// Why names what the path holds, so the report explains the refusal.
Why string
}
Held is a change preen refused to plan because its path holds generated output, recorded with the reason so the plan can say why.
A held change stays in the working tree exactly as it was, and it still counts toward the coverage check, so holding one back cannot quietly drop work: the plan accounts for it, it is shown before approval, and the content hash the run conserves still includes it.
type Hunk ¶
type Hunk struct {
// Index is the hunk's position when the plan was built, used for display
// and for reporting a hunk that later goes missing.
Index int
// Body is the hunk's lines without its header, the identity used to find
// the hunk again at apply time.
Body string
}
Hunk identifies one hunk a commit takes from a file.
The hunk is identified by its body rather than its position, because committing an earlier hunk shifts the line numbers of every hunk after it. The body is stable across that shift, so it still finds the right hunk in a diff regenerated mid-run.
type Part ¶
type Part struct {
// Path is the file, relative to the repository root.
Path string
// From is the rename source, empty unless the change moves a file.
From string
// Kind is what happened to the path.
Kind repo.Kind
// Hunks are the file's hunks this commit takes. An empty selection means
// the whole file.
Hunks []Hunk
}
Part is one file's contribution to a commit, either the whole file or a chosen subset of its hunks.
type Plan ¶
type Plan struct {
// Base is the commit the run resets to, empty for a working-tree-only run.
Base string
// Backup is the recovery ref created before anything moved.
Backup string
// MergeSummary is the mandatory merge audit line for any run that resets.
MergeSummary string
// Absorbed are the existing commits the run will redo.
Absorbed []repo.Commit
// Commits are the planned commits, in the order they will be recorded.
Commits []Commit
// Leftover are changes deliberately left uncommitted.
Leftover []Part
// Held are changes left uncommitted because they hold generated output,
// each with the pattern that caught it.
Held []Held
// Push is the exact force push a published rewrite will run, empty for any
// run that does not publish.
Push string
// Debris are lines that look like leftovers from the session, reported so
// they can be dealt with before they are committed. They are never removed
// automatically.
Debris []string
// Covers is the change set the plan was built against, kept so an edit can
// be revalidated without surveying the repository again.
Covers []repo.Change
}
Plan is the full intent of a run.
func (*Plan) DropPath ¶
DropPath removes a path from every commit and records it as deliberately left uncommitted, which keeps the plan accounting for the whole tree.
func (*Plan) LeavePath ¶
LeavePath records a change as deliberately left uncommitted whether or not a commit holds it yet. DropPath alone cannot do that for a change no commit took, which is what a grouping answer that leaves a scratch file out entirely produces.
func (*Plan) MergeInto ¶
MergeInto folds commit number from into commit number into, keeping the destination's message and appending the source's parts.
func (Plan) Render ¶
Render writes the plan for approval. It leads with what will move, since the reset and the backup ref are what a reader needs to judge the risk, then lists the commits in the order they will be recorded.
func (*Plan) Reorder ¶
Reorder rearranges the commits into the given 1-based order, which must be a permutation of the existing numbers.
func (Plan) Resets ¶
Resets reports whether the plan moves the branch, which is what makes the merge audit and the backup ref mandatory.
func (Plan) Revalidate ¶
Revalidate checks the plan against the change set it was built for, which is how an edit is rejected before it can lose work.
func (*Plan) SplitByFile ¶
SplitByFile breaks a commit into one commit per file it touches, keeping the original subject with the path appended so each is still named.
func (Plan) Validate ¶
Validate checks that the plan is internally coherent and covers exactly the supplied set of changes: every change lands in a commit, a leftover, or a held path, nothing lands twice, and no commit is empty.
This is the check that keeps a grouping mistake from silently dropping work, and it runs before the repository is touched. Held paths are counted here for that reason: a path preen declines to commit is still a path it has to account for out loud.