Skip to content
go-libfossil Artifact [f6b838cd77]
Login

Artifact [f6b838cd77]

Artifact f6b838cd77e39b9d4e50421e4d6f600f2cbe566fbabae8b1fd3ca4b17d99c993:


package libfossil

import (
	"context"
	"fmt"

	"github.com/danmestas/go-libfossil/internal/content"
)

// CompactStore explicitly reclaims held file content outside the store cone
// (draft-fossil-sparse-cone-00 ยง5.4). It returns the number of artifacts changed
// to recoverable phantoms, preserving their identities for a later pull.
// Setting or narrowing a cone alone never reclaims content.
//
// Spines, control artifacts, tree nodes, shared in-cone content, unpublished or
// private content, and retained delta dependencies stay held. A dense store or
// lost cone is a no-op. Corruption or an incomplete spine aborts compaction.
// All changes run in one write transaction and roll back on error or observed
// cancellation. SQLite's configured busy timeout bounds waiting for its writer
// lock; cancellation is checked before and after that wait, not within it.
// Reclaimed bytes become reusable database space, not a guaranteed smaller file.
func (r *Repo) CompactStore(ctx context.Context) (int, error) {
	count, err := content.CompactStore(ctx, r.inner.DB())
	if err != nil {
		return 0, fmt.Errorf("libfossil: compact store: %w", err)
	}
	return count, nil
}