snapshot

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package snapshot captures immutable file trees from a Git repository. A Tree owns a private copy of every file's bytes, so a consumer can read the captured content and mode without being able to mutate the snapshot or the caller's original data. It captures four universes: the working tree, the stage-0 index, an arbitrary commit, and a first-parent before/after range pair. Each is the complete selected file set; consumers apply their own eligibility filters.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedMode reports a File whose Mode is not representable.
	ErrUnsupportedMode = errors.New("snapshot: unsupported file mode")
	// ErrUnsafePath reports a File whose path is empty, absolute, or escapes
	// the tree root through traversal or a non-canonical form.
	ErrUnsafePath = errors.New("snapshot: unsafe path")
	// ErrDuplicatePath reports two Files sharing one path.
	ErrDuplicatePath = errors.New("snapshot: duplicate path")
)

Construction faults. NewTree returns one of these when a File would make the snapshot ambiguous or unsafe to address by path.

Functions

This section is empty.

Types

type File

type File struct {
	Path  string
	Mode  Mode
	Bytes []byte
}

File is one file in a Tree: a repo-relative slash path, its Mode, and a private copy of its bytes.

func (File) Scannable

func (f File) Scannable() bool

Scannable reports whether authority parsers may inspect this file's bytes.

type Mode

type Mode uint8

Mode is the file mode a Tree preserves. Symlink bytes are inert targets.

const (
	// Regular is an ordinary, non-executable file.
	Regular Mode = iota
	// Executable is a file with the executable bit set.
	Executable
	// Symlink is an inert symbolic link whose bytes are its target.
	Symlink
)

type Tree

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

Tree is an immutable, path-sorted set of files. Build one with NewTree; its Lookup and List methods hand out byte copies so callers cannot reach the captured content.

func CommitTree

func CommitTree(repoRoot, rev string) (*Tree, error)

CommitTree captures the committed tree that rev resolves to as an immutable Tree. It reads only committed content, never the working tree, so a commit or HEAD universe is reproducible regardless of local edits. Ordinary and executable, and symlink files are included with their mode preserved; symlink bytes are inert targets and gitlinks are skipped.

func IndexTree

func IndexTree(repoRoot string) (*Tree, error)

IndexTree captures the repository's stage-0 index as an immutable Tree. Ordinary, executable, and symlink files are included with mode preserved; symlink bytes are inert targets and gitlinks are skipped; an unmerged or unreadable index is rejected. Path selection and ordering come from git.IndexBlobs, which opens the repository through git.OpenRepo and so resolves a linked worktree's index like any other command.

func NewTree

func NewTree(files []File) (*Tree, error)

NewTree validates files, copies each one's bytes, and returns a path-sorted Tree. It rejects an unsupported mode, an unsafe path, or a duplicate path so every file is addressable by exactly one canonical relative path.

func RangePair

func RangePair(repoRoot, rev string) (before, after *Tree, err error)

RangePair captures the before and after Trees for the transition into the commit rev resolves to: after is that commit's tree and before is its first-parent tree, or an empty Tree for a root commit. Merges follow the first parent only, so a transition committed on a branch and merged is still observed at the merge. Both are committed universes; neither reads working bytes.

func WorkingTree

func WorkingTree(repoRoot string) (*Tree, error)

WorkingTree captures the repository's working universe as an immutable Tree: every tracked-and-present or nonignored-untracked file, with executable and symlink modes preserved. Symlinks are not followed; their target is retained as inert bytes. Deleted, ignored, and nested-repository paths are excluded by git.WorkingPaths. It is the complete selected filesystem universe; generated, contextIgnore, and other eligibility filters are applied by downstream consumers, not here.

func (*Tree) List

func (t *Tree) List() []File

List returns every file in path order, each with a byte copy.

func (*Tree) Lookup

func (t *Tree) Lookup(p string) (File, bool)

Lookup returns the file at the exact path and whether it exists. The returned File carries a byte copy.

Jump to

Keyboard shortcuts

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