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 ¶
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 ¶
GlobBaseDirs extracts the non-wildcard base directory from each glob pattern for use as walk roots.
Types ¶
type ContentSnap ¶
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.