Artifact f33a72e98862aaf22bf1597bc73ecda1619454ab8f67b1acf7c57b5c9341dca9:
- File
repo_sparse.go
— part of check-in
[e5904fc85b]
at
2026-10-22 14:47:23
on branch feat/horizon-cones
— feat(horizon): expose content horizons in the public API and CLI
A store cone could carry a horizon only through internal/cone, so library users and the CLI had no way to clone into or edit a content-horizon store. Add Horizon, HorizonRule, NewHorizonCone, Cone.Horizon and Cone.WithHorizon over the internal cone (always the content cut), carry it through SetStoreCone/SetStoreConeContext (deepening fetches what the older check-in keeps) and CloneOpts.StoreCone, and add --horizon, --leaves, --no-horizon and --cone to repo clone and repo cone store.
A horizon is a property of the store, not of a checkout (draft-fossil-horizon-00 3.2), so checkout cones carrying one are refused with ErrHorizonCheckout, and widening the store from a checkout cone keeps the store's horizon. (user: [email protected], size: 3213) [annotate] [blame] [check-ins using] [more...]
package libfossil import ( "context" "errors" "fmt" "github.com/danmestas/go-libfossil/internal/content" internalsync "github.com/danmestas/go-libfossil/internal/sync" ) // SettingPartialMirror names the boolean repository setting, read as fossil // reads one ("on", "yes", "true" or a nonzero number), that lets a sparse store // serve a clone its cone does not cover (draft-fossil-sparse-cone-00 §5.3). // Unset, such a clone is refused with one error card and no content, since // the clone would receive elided phantoms it must resolve elsewhere. It // governs every serving surface: HandleSync, XferHandler and ServeHTTP. const SettingPartialMirror = internalsync.SettingPartialMirror // 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). // // A cone may carry a horizon (draft-fossil-horizon-00): setting one elides // blobs only check-ins below it name, and SetStoreCone moves no content, as // for any narrowing. Setting an older check-in, or nil, widens, and // SetStoreConeContext fetches what the deeper horizon keeps. 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 }