Artifact 981e99428f063acd7ff47d597a2225f7bf2b9f83cf4166cb11891daeda3c9ccb:
- File
internal/verify/verify.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 2167) [annotate] [blame] [check-ins using]
// Package verify provides comprehensive repository verification and rebuild. package verify import ( "time" libfossil "github.com/danmestas/libfossil/internal/fsltype" "github.com/danmestas/libfossil/internal/repo" ) // IssueKind categorizes the type of verification issue found. type IssueKind int const ( IssueHashMismatch IssueKind = iota IssueBlobCorrupt IssueDeltaDangling IssuePhantomOrphan IssueEventMissing IssueEventMismatch IssueMlinkMissing IssuePlinkMissing IssueTagxrefMissing IssueFilenameMissing IssueLeafIncorrect IssueMissingReference ) // Issue represents a single verification problem found in the repository. type Issue struct { Kind IssueKind RID libfossil.FslID UUID string Table string Message string } // Report contains the results of a repository verification pass. type Report struct { Issues []Issue BlobsChecked int BlobsOK int BlobsFailed int BlobsSkipped int MissingRefs int TablesRebuilt []string Duration time.Duration } // OK returns true if no issues were found during verification. func (r *Report) OK() bool { return len(r.Issues) == 0 } // addIssue appends a new issue to the report. func (r *Report) addIssue(issue Issue) { r.Issues = append(r.Issues, issue) } // Verify performs comprehensive repository verification. // It checks blob integrity, delta chains, phantom records, and derived tables. // Returns a report of all issues found. Never stops early - reports all problems. func Verify(r *repo.Repo) (*Report, error) { if r == nil { panic("verify: nil repo") } start := time.Now() report := &Report{} // Phase 1: Blob integrity (content hash verification) if err := checkBlobs(r, report); err != nil { return nil, err } // Phase 2: Structural integrity (delta chains, phantoms) if err := checkDeltaChains(r, report); err != nil { return nil, err } if err := checkPhantoms(r, report); err != nil { return nil, err } // Phase 3: Derived tables (event, mlink, plink, tagxref, filename, leaf) if err := checkDerived(r, report); err != nil { return nil, err } report.Duration = time.Since(start) return report, nil }