Artifact 28bc244a5235fdcdac8f953b94c66aad02054c4a10ebfe0051b8a183e9a82ff2:
- File
repo.go
— part of check-in
[d367012009]
at
2026-10-25 23:10:47
on branch feat/read-blob-content-cache
— feat: read an artifact by hash and cache content on Repo
Repo.ReadBlob expands one artifact by its full hash after the availability check ReadFile applies, and names an unknown hash with ErrArtifactNotFound.
Repo.SetContentCache attaches a byte-bounded content.Cache that ReadFile, ReadFileAt, ReadBlob, ListFiles, Diff and Annotate share; check-in parses are kept in its derived memo, so reads at one check-in parse the manifest once. Default off. A read that finds the DB's finished-write count moved swaps in an empty cache, so a purged, compacted or elided artifact, and a rid SQLite reuses after a purge, is never served from it. Writes by another process are not seen; the method's doc says so.
Tracked in #492. (user: [email protected], size: 2198) [annotate] [blame] [check-ins using] [more...]
package libfossil import ( "sync/atomic" "github.com/danmestas/go-libfossil/db" "github.com/danmestas/go-libfossil/internal/repo" ) // Repo is an opaque handle to a Fossil repository. type Repo struct { inner *repo.Repo path string // cache is the content cache SetContentCache attached, nil when off. cache atomic.Pointer[contentCache] } // CheckpointMode mirrors SQLite's PRAGMA wal_checkpoint(<mode>) argument. type CheckpointMode = db.CheckpointMode const ( CheckpointPassive = db.CheckpointPassive CheckpointFull = db.CheckpointFull CheckpointRestart = db.CheckpointRestart CheckpointTruncate = db.CheckpointTruncate ) // Path returns the filesystem path to the repository file. func (r *Repo) Path() string { return r.path } // Inner returns the underlying internal repo handle. // This is exported for use by in-module packages (e.g., cli/) that need // direct access to the repo DB for raw SQL or internal package calls. func (r *Repo) Inner() *repo.Repo { return r.inner } // Close closes the repository and releases resources. As part of close, // a WAL TRUNCATE checkpoint is run so the on-disk repo file is readable // by external fossil/SQLite tooling. func (r *Repo) Close() error { if r.inner == nil { return nil } return r.inner.Close() } // Checkpoint runs PRAGMA wal_checkpoint(<mode>) against the repository. // Safe to call on a live repo. CheckpointPassive is non-blocking and // appropriate for periodic background checkpoints. CheckpointTruncate // produces a maximally compact on-disk file readable by external fossil // tooling without a subsequent Close. func (r *Repo) Checkpoint(mode CheckpointMode) error { if r.inner == nil { return nil } return r.inner.Checkpoint(mode) } // DB returns the underlying database handle for raw SQL queries. // Use this when the high-level Repo methods don't cover your use case. func (r *Repo) DB() *db.DB { return r.inner.DB() } // WithTx executes fn within a database transaction. func (r *Repo) WithTx(fn func(tx *db.Tx) error) error { return r.inner.WithTx(fn) } // Verify checks repository integrity (blob checksums, delta chains). func (r *Repo) Verify() error { return r.inner.Verify() }