Artifact 418499921ed4a65a210fa3f845023acb678dd42866218e806bd4ad6cc044a85c:
- File
internal/fsltype/fsltype.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: 2759) [annotate] [blame] [check-ins using]
// Package fsltype defines shared types used across internal packages. // These are re-exported by the root libfossil package. package fsltype import ( "math" "time" ) // FslID is a row-id in the blob table (content-addressed artifacts). type FslID int64 // FslSize represents a blob size; negative values indicate phantom blobs. type FslSize int64 const ( // PhantomSize is the sentinel size for phantom (not-yet-received) blobs. PhantomSize FslSize = -1 // FossilApplicationID is the SQLite application_id for Fossil repositories. FossilApplicationID int32 = 252006673 ) // EventKind is the type discriminator on the event table's newest-first // timeline: one of the single-letter codes fossil assigns per row (see // src/schema.c:303-312). The zero value ("") means "all kinds" — the // canonical default a bare `fossil timeline` uses when no -t/--type is // given (src/timeline.c:timeline_cmd(), guarded by `zType && zType[0]!='a'`). type EventKind string const ( // EventKindCheckin is a check-in ('ci'). EventKindCheckin EventKind = "ci" // EventKindTechnote is a technote / event artifact ('e'). EventKindTechnote EventKind = "e" // EventKindForum is a forum post ('f'). EventKindForum EventKind = "f" // EventKindTag is a tag/control artifact ('g'). EventKindTag EventKind = "g" // EventKindTicket is a ticket change ('t'). EventKindTicket EventKind = "t" // EventKindWiki is a wiki page edit ('w'). EventKindWiki EventKind = "w" ) // Valid reports whether k is the zero value ("all kinds") or one of the // six recognized event.type codes. func (k EventKind) Valid() bool { switch k { case "", EventKindCheckin, EventKindTechnote, EventKindForum, EventKindTag, EventKindTicket, EventKindWiki: return true default: return false } } const julianEpoch = 2440587.5 // TimeToJulian converts a time.Time to a Fossil Julian day number. func TimeToJulian(t time.Time) float64 { return julianEpoch + float64(t.UTC().UnixMilli())/(86400.0*1000.0) } // JulianToTime converts a Fossil Julian day number to time.Time. // // Rounds to the nearest millisecond rather than truncating: a julian value // produced by TimeToJulian for an exact millisecond carries float64 error // on the order of 1e-10 days, which a plain int64() truncation can turn // into a full millisecond of drift when that error lands the value just // below the true integer. Rounding makes the pair a true round trip // (TimeToJulian(JulianToTime(m)) == m) for any m that itself came from // TimeToJulian — the property the Timeline enumeration's composite // (mtime, rid) pagination cursor depends on. func JulianToTime(j float64) time.Time { millis := int64(math.Round((j - julianEpoch) * 86400.0 * 1000.0)) return time.UnixMilli(millis).UTC() }