Artifact f0e9ce09bc0317d4b654cc4b5933f2a88f87c5c992d3403e32002f60a1ac78da:
- File
examples/wasm/main.go
— part of check-in
[9a2697c556]
at
2026-07-19 16:00:36
on branch trunk
— fix: split repository enumeration from ancestry walking (#45) (#54)
Repo.Timeline was an ancestry walk wearing an enumeration's name: it required a start rid, emitted that check-in, followed plink where isprim=1 to the primary parent, and repeated until the chain ended. It never touched the event table and never visited a second parent or a sibling branch head, so it silently omitted any check-in that wasn't a first-parent ancestor of the given start rid — on libfossil's own repository that was 577 of 3,761 check-ins, with no error and no warning. The limit option never bound because the (wrong) walk exhausted first.
Split into two operations under honest names:
- Repo.Timeline(TimelineOpts) enumerates the event table newest first, every kind by default or a single kind via Type. This matches canonical `fossil timeline`'s -t/--type default (a filter only applies when given and not 'a'). - Repo.Ancestry(LogOpts) keeps the original first-parent walk, unchanged in behavior, under a name that says what it does.
Breaking change, no deprecated shim (pre-1.0, clean break): callers of the old Timeline(LogOpts) need to move to Ancestry(LogOpts) if they want the walk, or to Timeline(TimelineOpts) if they want the enumeration fossil's own timeline command performs. The only in-tree callers were the `repo timeline` CLI command and the two examples; all three are migrated to Timeline(TimelineOpts). See CHANGELOG.md.
LogEntry gains a Kind field identifying which of event.type's six kinds (ci, e, f, g, t, w) an entry is; Parents is only populated for check-ins, since plink only relates check-in artifacts.
Timeline's pagination cursor orders by (mtime DESC, rid DESC) instead of canonical fossil's bare mtime DESC with no tie-break — a deliberate improvement, not an oversight, since fossil's web cursor combines that missing tie-break with a one-second timestamp slop and can repeat or skip rows at a page boundary. Getting the composite cursor to actually round-trip losslessly required fixing a real bug along the way: JulianToTime truncated instead of rounded when converting a julian day back to milliseconds, so TimeToJulian(JulianToTime(m)) was not always equal to m even for exact-millisecond inputs — enough to misplace a row at a page boundary under exactly the same-mtime conditions this issue's acceptance criteria test for. Fixed to round to nearest. Because the same class of drift also appears in the ncruces/WASM sqlite driver's own internal REAL-to-time.Time conversion (independent of this library's code), the cursor comparison also carries a small explicit tolerance rather than relying on bit-exact equality across drivers.
Both the ancestry walk's loop and the enumeration's row loop now carry an explicit, testable bound so a corrupt or cyclic plink table can't hang the process. (user: [email protected], size: 2275) [annotate] [blame] [check-ins using]
// Example: build libfossil for a generic WASI Preview 1 wasm target. // // Target: GOOS=wasip1 GOARCH=wasm. The pure-Go modernc.org/sqlite driver // uses syscalls not available under wasip1, so this example uses the // ncruces driver, which ships SQLite itself as WebAssembly and is the // supported backend for wasip1/js builds. package main import ( "log" "os" "path/filepath" "github.com/danmestas/libfossil" _ "github.com/danmestas/libfossil/db/driver/ncruces" ) func main() { // Use a fixed relative path inside whatever directory the WASI runtime // mapped in (e.g. wasmtime --dir=.). os.MkdirTemp is unreliable on // some WASI runtimes, so clear any stale file up front. repoPath := filepath.Join(".", "demo.fossil") _ = os.Remove(repoPath) defer os.Remove(repoPath) created, err := libfossil.Create(repoPath, libfossil.CreateOpts{User: "wasi"}) if err != nil { log.Fatalf("create: %v", err) } if err := created.Close(); err != nil { log.Fatalf("close after create: %v", err) } log.Printf("created repo at %s", repoPath) repo, err := libfossil.Open(repoPath) if err != nil { log.Fatalf("open: %v", err) } defer repo.Close() // Every fresh repo has an auto-generated project-code in the config table. projectCode, err := repo.Config("project-code") if err != nil { log.Fatalf("config project-code: %v", err) } log.Printf("project-code: %s", projectCode) // Commit one file to exercise blob insert, manifest parse, and deltas // on top of the ncruces SQLite VFS. rid, uuid, err := repo.Commit(libfossil.CommitOpts{ Files: []libfossil.FileToCommit{{Name: "hello.txt", Content: []byte("hello from wasip1\n")}}, Comment: "initial commit from wasi", User: "wasi", }) if err != nil { log.Fatalf("commit: %v", err) } log.Printf("commit rid=%d uuid=%s", rid, uuid) entries, err := repo.Timeline(libfossil.TimelineOpts{Limit: 10}) if err != nil { log.Fatalf("timeline: %v", err) } for _, e := range entries { log.Printf("timeline: %s %s — %s", e.Time.Format("2006-01-02 15:04:05"), e.UUID[:12], e.Comment) } files, err := repo.ListFiles(rid) if err != nil { log.Fatalf("list files: %v", err) } for _, f := range files { log.Printf("file: %s (%s)", f.Name, f.UUID[:12]) } log.Println("done") }