types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package types defines the core data structures shared across git-branch-tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ModeStrings

func ModeStrings() []string

ModeStrings returns a slice of all String values of the enum

func RendererStrings

func RendererStrings() []string

RendererStrings returns a slice of all String values of the enum

Types

type BranchCommitMap

type BranchCommitMap map[BranchName][]CommitHash

BranchCommitMap maps each branch to its commit history, ordered from HEAD (index 0) to the initial commit.

type BranchInfo

type BranchInfo struct {
	// Name is the canonical branch name, used as a lookup key.
	Name BranchName

	// DisplayName is the name as printed; may contain ANSI colour codes.
	DisplayName string

	// LatestAncestor is the parent branch in the tree; empty string for roots.
	LatestAncestor BranchName

	// HEAD is the hash of the tip commit of the branch.
	HEAD CommitHash
}

BranchInfo holds display and ancestry metadata for a single branch.

type BranchInfoMap

type BranchInfoMap map[BranchName]*BranchInfo

BranchInfoMap maps a branch name to its BranchInfo.

type BranchInfosMap

type BranchInfosMap map[BranchName][]*BranchInfo

BranchInfosMap maps a branch name to all BranchInfos that have it as their LatestAncestor.

type BranchName

type BranchName string

BranchName is a git branch name. It is a short name by default, or a full ref (e.g. refs/heads/main) when FullRefs is enabled.

type BranchNamesSet

type BranchNamesSet map[BranchName]struct{}

BranchNamesSet is a set of branch names.

func (BranchNamesSet) Equals

func (bns BranchNamesSet) Equals(bns2 BranchNamesSet) bool

Equals reports whether bns and bns2 contain exactly the same branch names.

type Commit

type Commit struct {
	// Hash is the commit's hash.
	Hash CommitHash

	// BranchNames is the set of all branches whose history includes this commit.
	BranchNames BranchNamesSet
}

Commit holds metadata about a single git commit.

type CommitHash

type CommitHash string

CommitHash is a full git commit hash.

type CommitHashMap

type CommitHashMap map[CommitHash]*Commit

CommitHashMap maps each commit hash to its Commit metadata.

type CommitToBranchInfoMap

type CommitToBranchInfoMap map[CommitHash]*BranchInfo

CommitToBranchInfoMap maps a commit hash to the BranchInfo of the branch whose HEAD is that commit. Used during node collapsing.

type Mode

type Mode int

Mode controls how parent-child relationships between branches are determined.

const (
	// History means that we'll infer ancestry from shared git commit history.
	History Mode = iota

	// Upstream uses each branch's configured upstream (git branch --set-upstream-to).
	Upstream
)

func ModeString

func ModeString(s string) (Mode, error)

ModeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ModeValues

func ModeValues() []Mode

ModeValues returns all values of the enum

func (Mode) IsAMode

func (i Mode) IsAMode() bool

IsAMode returns "true" if the value is listed in the enum definition. "false" otherwise

func (Mode) String

func (i Mode) String() string

type Node

type Node struct {
	// Val is the node's value - a BranchInfo.
	Val *BranchInfo

	// ChildNodes is a list of this node's children.
	ChildNodes []*Node
}

Node is a tree node that satisfies the ppds.Node interface. It is used as the common in-memory tree representation passed to all renderers.

func (*Node) Children

func (n *Node) Children() []ppdstree.Node

Children returns the node's children as a []ppdstree.Node slice, satisfying the ppds.Node interface. See https://github.com/golang/go/wiki/InterfaceSlice for why the conversion cannot be done more directly.

func (*Node) Data

func (n *Node) Data() any

Data returns the node's display name, satisfying the ppds.Node interface.

type NodeMap

type NodeMap map[BranchName]*Node

NodeMap maps a branch name to its Node. The empty-string key ("") is the synthetic root node used by renderers that walk the map directly (GoTree, TreeDrawer, TreePrint).

type Renderer

type Renderer int

Renderer selects which third-party library is used to draw the branch tree.

const (
	// GoTree is github.com/d6o/GoTree.
	GoTree Renderer = iota

	// TreeDrawer is github.com/m1gwings/treedrawer (no colour support).
	TreeDrawer

	// PPDSVertical is github.com/shivamMg/ppds, vertical layout.
	PPDSVertical

	// PPDSHorizontal is github.com/shivamMg/ppds, horizontal layout.
	PPDSHorizontal

	// PPDSHorizontalNewline is github.com/shivamMg/ppds, horizontal layout with newlines (default).
	PPDSHorizontalNewline

	// TreePrint is github.com/xlab/treeprint.
	TreePrint
)

func RendererString

func RendererString(s string) (Renderer, error)

RendererString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func RendererValues

func RendererValues() []Renderer

RendererValues returns all values of the enum

func (Renderer) IsARenderer

func (i Renderer) IsARenderer() bool

IsARenderer returns "true" if the value is listed in the enum definition. "false" otherwise

func (Renderer) String

func (i Renderer) String() string

type UpstreamMap

type UpstreamMap map[BranchName]BranchName

UpstreamMap maps each branch to its upstream tracking branch. An empty string value means the branch has no upstream and is treated as a root.

Jump to

Keyboard shortcuts

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