diff

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package diff provides mtime+size snapshot diffing for attributing concurrent file writes. Not cryptographic; use cache.Hash for exact-content guarantees.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Changed

func Changed(pre, post Snap) []string

Changed returns paths added or modified between pre and post. Deletions are not reported.

func DiffContent

func DiffContent(pre, post ContentSnap) []string

DiffContent returns paths whose content differs between pre and post (added/removed counts as different).

func GlobBaseDirs

func GlobBaseDirs(root string, globs []string) []string

GlobBaseDirs extracts the non-wildcard base directory from each glob pattern for use as walk roots.

Types

type ContentSnap

type ContentSnap map[string][32]byte

ContentSnap is a SHA-256 snapshot per path; used for determinism replay where mtime+size is insufficient.

func HashContent

func HashContent(ctx context.Context, sets []OutputGlobs) (ContentSnap, error)

HashContent returns a SHA-256 digest per regular file matching one of the declared output globs in sets. A malformed glob is an error; a glob matching nothing is not.

It expands globs exactly the way the cache snapshot does (internal/cache/snapshot.go): glob against the root, and where a match is a DIRECTORY, take every file beneath it. That agreement is the point. An earlier version walked base directories and matched each file against the pattern, which reads as equivalent and is not: `*` does not cross a separator, so a declared "dist/*" matched the cache's `dist/linux_amd64/` directory and none of the files inside it. The replay then compared an empty snapshot and reported the target deterministic, and the workaround was to widen a declaration that had been right all along.

Globbing rather than walk-then-filter also makes the malformed-glob promise unconditional: doublestar.Glob reports ErrBadPattern whether or not anything matches, where a matcher only consulted per walked file could hide a typo behind an earlier glob that matched, or behind an empty output directory.

type OutputGlobs added in v0.4.0

type OutputGlobs struct {
	Root  string   // absolute
	Globs []string // relative to Root, as the magusfile declared them
}

OutputGlobs is one root directory and the declared output globs RELATIVE to it.

Relative because the root is a literal path and a glob is a pattern: joining them fed the checkout's own directory name to the glob engine, so a repository under a path containing `[`, `]`, `{` or `}` matched nothing and the replay passed having hashed zero files. doublestar has no QuoteMeta, so keeping the root out of the pattern is the only fix that covers the whole class. Globbing against os.DirFS(Root) also makes a `..` glob unable to reach outside the root at all.

A slice, not one root, because a target may declare an output into another project's tree.

type Snap

type Snap map[string]int64

Snap is a snapshot of files keyed by absolute path; values pack mtime_ns and size into one int64.

func Take

func Take(dirs []string) Snap

Take walks each directory in dirs and records the current mtime+size for every regular file found. Directories that do not exist are silently skipped. Symlinks are not followed.

Jump to

Keyboard shortcuts

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