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 ¶
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 ¶
File is one file in a Tree: a repo-relative slash path, its Mode, and a private copy of its bytes.
type Mode ¶
type Mode uint8
Mode is the file mode a Tree preserves. Symlink bytes are inert targets.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.