Artifact c9fc40ba1f60dc698a48c9eb1f0a32ce3daf8c408712389804e15631d70d90e5:
- File
repo_sparse.go
— part of check-in
[774f579bfa]
at
2026-10-21 11:44:51
on branch feat/submanifest-reader
— feat(sparse): expose narrow-then-compact as Repo.CompactStore and repo cone compact
The public entry point refuses a dense store, as zit's pack --drop-elided does, and drops exactly the blobs that only out-of-cone F cards name. The test computes that set from the held artifacts, then verifies the store and recovers every dropped payload by widening through SetConeContext. (user: [email protected], size: 2340) [annotate] [blame] [check-ins using]
package libfossil import ( "context" "errors" "fmt" "github.com/danmestas/go-libfossil/internal/content" ) // StoreCone returns the repository's store cone, or nil when the store is // dense. A store cone (draft-fossil-sparse-cone-00 §5) is local policy: an // artifact the cone leaves out may be deliberately absent, an elided phantom, // which synchronization does not request and verification counts apart from // damage. A cone this version cannot read is lost policy and reads as nil, so // the store heals toward dense. func (r *Repo) StoreCone() (*Cone, error) { inner, err := content.StoreCone(r.inner.DB()) if err != nil { return nil, fmt.Errorf("libfossil: store cone: %w", err) } return wrapCone(inner), nil } // SetStoreCone replaces the store cone; nil makes the store dense. It moves // no content. Narrowing deletes nothing (§5.4). Widening makes the newly // covered elided phantoms wanted again, and the next pull fetches them. // While a cone is set, a commit carries no R card (§4.3). func (r *Repo) SetStoreCone(c *Cone) error { if err := content.SetStoreCone(r.inner.DB(), unwrapCone(c)); err != nil { return fmt.Errorf("libfossil: set store cone: %w", err) } return nil } // ErrNoStoreCone is returned by CompactStore on a dense store: with no cone // on record nothing is elided, and compaction never guesses a policy. var ErrNoStoreCone = errors.New("libfossil: the store has no cone") // CompactStore is the narrow-then-compact deletion (§5.4), the only one the // sparse draft defines: it turns held blobs that only out-of-cone F cards name // into elided phantoms and returns how many it dropped. Structural artifacts, // sub-manifest nodes whose cards prove an elision, unsent or private content // and the delta bases of retained artifacts stay held. A later widening // fetches the dropped blobs again; it is not reversible locally. func (r *Repo) CompactStore(ctx context.Context) (int, error) { if ctx == nil { panic("libfossil.Repo.CompactStore: nil context") } c, err := content.StoreCone(r.inner.DB()) if err != nil { return 0, fmt.Errorf("libfossil: compact store: %w", err) } if c == nil { return 0, ErrNoStoreCone } n, err := content.CompactStore(ctx, r.inner.DB()) if err != nil { return 0, fmt.Errorf("libfossil: compact store: %w", err) } return n, nil }