checkpoint

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 15 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 checkpoint snapshots working directories into shadow git repositories kept apart from the user's own repository, so file changes can be reviewed and undone. It never touches the user's index or history.

Index

Constants

View Source
const MaxFiles = 50000

MaxFiles is the most files a directory may hold to be snapshotted.

Variables

View Source
var ErrMissing = errors.New("the checkpoint is no longer available")

ErrMissing is returned for a snapshot the shadow repository no longer holds.

View Source
var ErrUnsupported = errors.New("checkpoints are not taken in this directory")

ErrUnsupported is returned for a directory that is not snapshotted: the home directory, a directory above it, the file system root, or one holding more than MaxFiles files.

Functions

This section is empty.

Types

type Change

type Change struct {
	Path    string `json:"path"`
	Status  Status `json:"status"`
	Added   int    `json:"added"`
	Deleted int    `json:"deleted"`
	Binary  bool   `json:"binary,omitempty"`
}

Change is one file a diff changes, by path relative to the working directory.

type Diff

type Diff struct {
	Changes []Change `json:"changes"`
	Patch   string   `json:"patch,omitempty"`
}

Diff is what changed between two states of a working directory.

type Status

type Status string

Status says how a diff changes a file.

const (
	StatusAdded    Status = "added"
	StatusModified Status = "modified"
	StatusDeleted  Status = "deleted"
)

type Store

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

Store keeps one shadow repository per work tree under its root.

func New

func New(root string) *Store

New keeps shadow repositories under root.

func (*Store) Compare

func (s *Store) Compare(ctx context.Context, dir string, trees []string) ([][]Change, error)

Compare reports, for each tree, what restoring it would change in dir now.

func (*Store) Diff

func (s *Store) Diff(ctx context.Context, dir, from, to string, paths ...string) (Diff, error)

Diff compares two snapshots of dir; an empty from or to is its current state. Paths, relative to dir, limit the diff.

func (*Store) Prune

func (s *Store) Prune(ctx context.Context, dir string, keep []string) error

Prune drops the refs of the snapshots of dir that keep does not name, and repeated refs of one tree, and at most once per gcInterval collects the objects no ref reaches.

func (*Store) Restore

func (s *Store) Restore(ctx context.Context, dir, tree string) ([]Change, error)

Restore brings dir back to tree: files changed or deleted since are written back, files added since are deleted. Ignored files and nested repositories are left alone. It returns what it changed.

func (*Store) Snapshot

func (s *Store) Snapshot(ctx context.Context, dir string) (string, error)

Snapshot records the current state of dir and returns its tree ID.

Jump to

Keyboard shortcuts

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