graph

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: GPL-3.0 Imports: 0 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 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

type Commit struct {
	Hash    string
	Parents []string
}

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

type Row struct {
	Commit  Commit
	Lane    int
	Matched bool
	Cells   []Glyph
}

Row is one rendered line: the commit, its lane index, and the glyph for each lane column. Cells is exactly Width() wide.

func Layout

func Layout(commits []Commit, matched map[string]bool) []Row

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.

func (Row) Width

func (r Row) Width() int

Width returns how many lane columns this row occupies.

Jump to

Keyboard shortcuts

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