Artifact 8a828cb6103dee875fca2acf3ff6fee46035c790f7eec3e943b3f722c7518e53:
- File
internal/search/trunk.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: 1915) [annotate] [blame] [check-ins using]
package search import ( "database/sql" "fmt" "strconv" libfossil "github.com/danmestas/libfossil/internal/fsltype" "github.com/danmestas/libfossil/db" ) // trunkTip returns the RID of the latest checkin on trunk. // Returns 0 if no trunk tip exists (empty repo). func trunkTip(q db.Querier) (libfossil.FslID, error) { if q == nil { panic("search.trunkTip: nil Querier") } var rid int64 err := q.QueryRow(` SELECT tagxref.rid FROM tagxref JOIN tag USING(tagid) WHERE tag.tagname = 'sym-trunk' AND tagxref.tagtype > 0 ORDER BY tagxref.mtime DESC LIMIT 1 `).Scan(&rid) if err == sql.ErrNoRows { return 0, nil } if err != nil { return 0, fmt.Errorf("trunkTip: %w", err) } if rid <= 0 { panic("search.trunkTip: postcondition: rid must be positive when row found") } return libfossil.FslID(rid), nil } // indexedRID returns the RID stored in fts_meta, or 0 if not set. func indexedRID(q db.Querier) (libfossil.FslID, error) { var val string err := q.QueryRow( "SELECT value FROM fts_meta WHERE key = 'indexed_rid'", ).Scan(&val) if err == sql.ErrNoRows { return 0, nil } if err != nil { return 0, fmt.Errorf("indexedRID: %w", err) } rid, err := strconv.ParseInt(val, 10, 64) if err != nil { return 0, fmt.Errorf("indexedRID parse: %w", err) } return libfossil.FslID(rid), nil } // NeedsReindex returns true if the trunk tip has advanced past the indexed checkin. // Returns false if the repo has no trunk tip (empty repo). func (idx *Index) NeedsReindex() (bool, error) { if idx == nil { panic("search.NeedsReindex: nil *Index") } tip, err := trunkTip(idx.repo.DB()) if err != nil { return false, fmt.Errorf("search.NeedsReindex: %w", err) } if tip == 0 { return false, nil // empty repo } current, err := indexedRID(idx.repo.DB()) if err != nil { return false, fmt.Errorf("search.NeedsReindex: %w", err) } return tip != current, nil }