commitgraph

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 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 commitgraph lays out and draws a Git history's revision graph: the lanes commits sit in and the lines joining them to their parents. It has no look: the app gives Graph its colors and builds the rows around it.

Index

Constants

View Source
const (
	// RowHeight is a row's height, which the lines span.
	RowHeight core.Points = 26
	// LaneWidth is a column's width.
	LaneWidth core.Points = 12
)

The graph's size by default, shared so the rows of a list line up.

View Source
const MaxLines = 64

MaxLines bounds a graph's open lines, so a history with very many open branches cannot widen it without limit.

Variables

This section is empty.

Functions

func Fold

func Fold(commits []Commit, collapsed map[string]bool) map[string]string

Fold returns the commits that each collapsed merge hides, mapped to that merge: those its later parents reach but its first parent does not. A commit stays shown when a shown commit other than the merge descends from it, so every shown line still reaches its parent.

func FormatDate

func FormatDate(cx *core.Scope, date time.Time) string

FormatDate writes a commit's date in local time, numerically in the language the app shows.

Types

type Commit

type Commit struct {
	Hash string
	// Parents are the commit's parents' hashes, the first parent first.
	Parents []string
}

Commit is what the graph knows of a commit. A history lists its commits newest first with each after its children, as `git log --date-order` does.

type Graph

type Graph struct {
	History *History
	// Item is the row's commit, read as a signal.
	Item func() Item
	// Height is the row's, RowHeight when 0, and Lane a column's width,
	// LaneWidth when 0.
	Height, Lane core.Points
	// Color returns a line's color, the text's when nil.
	Color func(line int) core.Color
	// Class, Style and StyleFunc are the graph's.
	Class     string
	Style     core.Style
	StyleFunc func() core.Style
	// MergeClass, MergeStyle and MergeStyleFunc are the merge button's,
	// such as its hover.
	MergeClass     string
	MergeStyle     core.Style
	MergeStyleFunc func() core.Style
}

Graph draws one commit's row of the revision graph: lines cross the row and curve into and out of the commit, a ring in its line's color. Its width is its own row's columns, so a busy stretch of history does not push every subject away from its graph; give each row of a list one Graph and no gap between them, so the lines meet.

A commit the History knows as a merge is a disc with a chevron, pointing down while expanded and right, inside a ring, while collapsed, and a button that toggles it. What the graph cuts out of itself shows the row behind it, selected or not.

func (Graph) Render

func (g Graph) Render(cx *core.Scope) core.Node

Render implements core.Node.

type History

type History struct {
	// contains filtered or unexported fields
}

History is a list of commits with its merges collapsed or expanded, and the graph of the commits that leaves shown. The app makes it with NewHistory and lists its rows with At.

func NewHistory

func NewHistory(cx *core.Scope, commits func() []Commit, selection *base.Selection) *History

NewHistory returns the history of commits, which it reads as signals, with every merge expanded. With a selection, one a collapsing merge hides moves to the merge.

func (*History) At

func (h *History) At(i int) Item

At returns the i-th shown commit, the zero Item past the end as a list's cell may read it while the history shrinks.

func (*History) Collapsed

func (h *History) Collapsed(hash string) bool

Collapsed reports whether the merge of hash hides the commits it brings in.

func (*History) Len

func (h *History) Len() int

Len returns how many commits show.

func (*History) Toggle

func (h *History) Toggle(hash string)

Toggle collapses or expands the merge of hash.

type Item

type Item struct {
	Index int
	Hash  string
	Row   Row
	// Merge reports that the commit has commits to collapse.
	Merge bool
}

Item is a shown commit of a History: its index in the history's commits and its graph.

type Line

type Line struct {
	ID, Top, Column, Bottom int
}

Line is one line crossing a commit's row: it enters the row's top edge in column Top, passes the row's middle in Column and leaves the bottom edge in Bottom. -1 means the line does not touch that edge, so it ends at the commit (no Bottom) or starts from it (no Top). ID keeps its color.

type Row

type Row struct {
	Lines                 []Line
	Column, Line, Columns int
}

Row is the graph of one commit: the lines crossing its row, the column of the commit itself and of the line it belongs to, -1 for a commit past MaxLines, which shows no node, and the number of columns the row draws in.

func Layout

func Layout(commits []Commit) []Row

Layout lays out the revision graph of commits and returns a row per commit. It keeps a line open for each parent still to come and numbers a new line by the column it opens in, so a branch takes that column's color and keeps it while open, and a merge folds it back into its first parent.

Jump to

Keyboard shortcuts

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