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

wtindex

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package wtindex gives a linked git worktree an index of its own, made from the index of another working tree of the same repository.

Prepare copies the other index as a pebble checkpoint into a temporary directory under the worktree root and syncs the copy with the worktree's files, when few enough files differ. Otherwise it returns a pending Build, whose Finish builds the index later. Either way the finished index is renamed to <worktree>/.codegraph, so a reader never opens one that is not complete.

Index

Constants

View Source
const (
	ReasonTooManyChanges = "too many files differ from the main checkout's index"
	ReasonMainLocked     = "another codegraph process holds the main checkout's index"
	ReasonMainOutdated   = "the main checkout's index needs a full rebuild"
	ReasonOtherDevice    = "the main checkout's index is on another filesystem"
)

The reasons a Build is pending.

Variables

View Source
var DefaultLimits = Limits{Foreground: 50, SeededFraction: 0.15}

DefaultLimits are the limits codegraph serve uses.

View Source
var ErrIndexExists = errors.New("wtindex: the worktree already has an index")

ErrIndexExists is returned by place when the root already holds an index. The seed directory is gone by then.

Functions

This section is empty.

Types

type Build

type Build struct {
	// Ready reports that <worktree>/.codegraph exists.
	Ready bool
	// Reason says why the build is pending. It is empty when Ready.
	Reason string
	// Changed and Total count the files that differ from the copied index
	// and the worktree's files. Prepare sets them only when it stopped its
	// sync because more than Limits.Foreground files changed.
	Changed, Total int
	// contains filtered or unexported fields
}

Build is the outcome of Prepare.

func Prepare

func Prepare(ctx context.Context, worktreeRoot, mainRoot string, lim Limits) (*Build, error)

Prepare gives the worktree at worktreeRoot an index made from the index of the working tree at mainRoot, when that takes at most lim.Foreground changed files. It returns a ready Build when <worktree>/.codegraph exists, and a pending Build when the index is left to Finish. It never changes mainRoot's index. An error means no index will be made, and the temporary directory is gone.

func (*Build) Finish

func (b *Build) Finish(ctx context.Context) error

Finish builds a pending index and places it. It syncs the copied index when at most lim.SeededFraction of the worktree's files changed, and indexes the worktree from scratch otherwise. It returns ctx's error, without placing the index, when ctx ends first. Another index that appears at the worktree root first wins, and Finish discards its own.

func (*Build) WorktreeRoot

func (b *Build) WorktreeRoot() string

WorktreeRoot is the root of the worktree the index is for.

type Limits

type Limits struct {
	// Foreground is the most changed files Prepare syncs before it
	// returns. It must be at least 1. More changed files leave the build
	// to Finish.
	Foreground int
	// SeededFraction is the largest share of changed files, out of the
	// worktree's files, for which Finish syncs the copied index. Above it,
	// Finish indexes the worktree from scratch.
	SeededFraction float64
}

Limits bound the work Prepare does before it returns, and choose how Finish builds the index.

Jump to

Keyboard shortcuts

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