index

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 10 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 index owns the branch→index mapping of a project's worktrees. The index feeds the port formula and the compose project name, so it must never change once a stack exists; this package allocates it once, records it in the registry, and recovers it from docker for worktrees that predate the recording.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoIndex = errors.New("no recorded index")

ErrNoIndex means the branch has no recorded index and no docker trace: as far as stacks are concerned, this worktree never started one.

Functions

func MatchBranch

func MatchBranch(labels []string, repoName, branch string) (int, string, bool)

MatchBranch finds the label belonging to this repo and branch among compose project labels. It extracts the candidate integer then rebuilds the canonical name, so stack.ProjectName stays the single naming authority.

Types

type Mode

type Mode int

Mode says whether a resolution may invent a new index. Commands that bring a stack up may; commands that address an existing stack (stop, remove, exec) must not, or they would "find" a stack that never existed.

const (
	MustExist Mode = iota
	MayAllocate
)

type Resolver

type Resolver struct {
	ConfigPath string
	Runner     execx.Runner
	Name       string // project name in the registry
	RepoName   string // filepath.Base of the project directory
	Out        io.Writer
}

Resolver answers "which index does this branch own" for one project.

func (*Resolver) Recorded

func (r *Resolver) Recorded() map[string]int

Recorded returns the saved branch→index map, for read-only display.

func (*Resolver) Release

func (r *Resolver) Release(branch string) error

Release forgets the branch's index once its worktree is removed.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, branch string, pos int, mode Mode) (int, error)

Resolve returns the branch's index. pos is the 1-based position git lists the worktree at (0 when unknown), used only as the historical fallback so worktrees created before indices were recorded keep the ports their .env already carries. Steps, first answer wins: recorded → backfill from docker labels → git position if free and clean → allocation (MayAllocate only).

Jump to

Keyboard shortcuts

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