Help us shape the future of Go! Take the 2026 Go Developer Survey

stack

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package stack holds the stack model and its on-disk store.

Index

Constants

View Source
const (
	RebaseJournal = "git-stack-rebase-state"
	ModifyJournal = "git-stack-modify-state"
)

Journal names for paused multi-step operations.

View Source
const FormatVersion = 1

FormatVersion is the current metadata file format.

Variables

This section is empty.

Functions

func ReadStateFile

func ReadStateFile(path string) ([]byte, error)

ReadStateFile reads a complete state file, allowing WriteAtomic to replace it while the read is in progress. On Windows, its handle permits delete sharing.

func WriteAtomic

func WriteAtomic(path string, data []byte) error

WriteAtomic publishes data at path using a fully written temporary file in the same directory. It preserves an existing regular file's permissions and uses 0644 for a new file. The parent directory must already exist. It does not acquire locks; callers must serialize mutations.

Types

type Branch

type Branch struct {
	Name string `json:"name"`
	// Base is the parent's tip SHA at the last restack. Commits after Base are this layer's own.
	Base   string `json:"base,omitempty"`
	CR     *CR    `json:"cr,omitempty"`
	Merged bool   `json:"merged,omitempty"`
}

Branch is one layer of a stack.

type CR

type CR struct {
	Number int    `json:"number"`
	URL    string `json:"url,omitempty"`
}

CR identifies the change request (pull or merge request) for a branch.

type File

type File struct {
	Version int      `json:"version"`
	Stacks  []*Stack `json:"stacks"`
}

File is the whole metadata file: every stack in the clone.

func (*File) Find

func (f *File) Find(branch string) *Stack

Find returns the stack containing branch, or nil.

func (*File) Remove

func (f *File) Remove(s *Stack)

Remove deletes s from the file.

func (*File) Resolve

func (f *File) Resolve(branch string) (*Stack, error)

Resolve finds the stack for branch, which may be a stack branch or a trunk used by exactly one stack.

type Stack

type Stack struct {
	Trunk    string    `json:"trunk"`
	Remote   string    `json:"remote"`
	Branches []*Branch `json:"branches"`
}

Stack is an ordered list of branches on top of a trunk; Branches[0] is the bottom.

func (*Stack) Active

func (s *Stack) Active() []*Branch

Active returns the unmerged branches, bottom first.

func (*Stack) Bottom

func (s *Stack) Bottom() *Branch

Bottom returns the lowest unmerged branch, or nil.

func (*Stack) Get

func (s *Stack) Get(name string) *Branch

Get returns the branch called name, or nil.

func (*Stack) Index

func (s *Stack) Index(name string) int

Index returns the position of name in s, or -1.

func (*Stack) Parent

func (s *Stack) Parent(name string) string

Parent returns the name of the nearest unmerged branch below name, or the trunk.

func (*Stack) Top

func (s *Stack) Top() *Branch

Top returns the topmost unmerged branch, or nil.

type Store

type Store struct {
	Dir string // git common dir
}

Store reads and writes the metadata file in the git common dir.

func (Store) ClearJournal

func (st Store) ClearJournal(name string) error

ClearJournal removes the named journal.

func (Store) HasJournal

func (st Store) HasJournal(name string) bool

HasJournal reports whether the named journal exists.

func (Store) Load

func (st Store) Load() (*File, error)

Load reads the metadata file. A missing file is an empty File.

func (Store) LoadJournal

func (st Store) LoadJournal(name string, v any) (bool, error)

LoadJournal reads the named journal into v. It reports false if there is none.

func (Store) Lock

func (st Store) Lock() (unlock func(), err error)

Lock serializes mutations across all worktrees of the clone with an OS file lock (flock, or LockFileEx on Windows), so a lock held by a process that died is released by the OS. It does not wait for a busy lock.

The lock file is left on disk on unlock: removing it would let two processes lock different inodes of the same path (see gh-stack's FileLock).

func (Store) Save

func (st Store) Save(f *File) error

Save writes f atomically.

func (Store) SaveJournal

func (st Store) SaveJournal(name string, v any) error

SaveJournal writes v as the named journal, atomically: a journal cut short would leave the paused operation impossible to continue or abort.

Jump to

Keyboard shortcuts

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