Documentation
¶
Overview ¶
Package graph lays a commit list out onto terminal columns ("lanes") so a renderer can draw the DAG the way `git log --graph` does (ADR-0037).
It is deliberately git-free and render-free: the input is an ordered commit list with parent hashes, the output is one Row per commit carrying the glyph for every lane column. That keeps the tricky part — lane bookkeeping — a pure function that can be tested against hand-written DAGs, and leaves colour, unicode-vs-ASCII, and width clipping entirely to the caller.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Commit ¶
Commit is the minimal shape Layout needs. It mirrors the fields of git.CommitMeta that matter for topology, so callers can adapt without this package importing internal/git (keeping it a leaf, like internal/tokens).
type Glyph ¶
type Glyph uint8
Glyph is what occupies one lane column on one row.
const ( // GlyphEmpty is an unused column. GlyphEmpty Glyph = iota // GlyphCommit is the commit's own marker; exactly one per row. GlyphCommit // GlyphVertical is a lane passing straight through this row. GlyphVertical // GlyphFork is a lane branching out to the right (a second parent leaving // the commit's lane). GlyphFork // GlyphMerge is a lane folding back in to the left (a lane whose commit // has been reached and that now rejoins). GlyphMerge )
type Row ¶
Row is one rendered line: the commit, its lane index, and the glyph for each lane column. Cells is exactly Width() wide.
func Layout ¶
Layout assigns each commit a lane and produces one Row per commit, in input order (which the caller is expected to have sorted newest-first, as git log does).
The algorithm is the standard one: `lanes` holds, per column, the hash that column is currently waiting to draw. When a commit is reached, it takes the leftmost lane already waiting for it; its first parent inherits that lane and every additional parent claims a new one (a fork). Any *other* lane also waiting for this commit is released — that is a merge point, where two lines of development converge.
matched marks which commits satisfied the caller's filter; a nil map means "everything matches", which is what an unfiltered run wants.
Commits whose parents are outside the input set (a truncated walk, or a range that starts mid-history) simply close their lane — the graph shows the boundary rather than inventing edges to commits it was never given.