Artifact 4b46b1dbcc47e8d5de8852ea3bddf8fa9df64f76280aee54033eb75a30c395e8:
- File
repo_checkout_test.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: 4712) [annotate] [blame] [check-ins using]
package libfossil import ( "path/filepath" "testing" _ "github.com/danmestas/libfossil/internal/testdriver" ) func TestCommitAndAncestry(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "test.fossil") r, err := Create(path, CreateOpts{User: "test"}) if err != nil { t.Fatal(err) } defer r.Close() rid1, uuid, err := r.Commit(CommitOpts{ Files: []FileToCommit{ {Name: "hello.txt", Content: []byte("hello world\n")}, }, Comment: "initial commit", User: "test", }) if err != nil { t.Fatal(err) } if uuid == "" { t.Fatal("Commit returned empty UUID") } if len(uuid) != 40 && len(uuid) != 64 { t.Errorf("UUID length = %d, want 40 or 64", len(uuid)) } if rid1 <= 0 { t.Fatalf("Commit returned rid=%d, want > 0", rid1) } // Second commit to test the ancestry walk. rid2, uuid2, err := r.Commit(CommitOpts{ ParentID: rid1, Files: []FileToCommit{ {Name: "hello.txt", Content: []byte("hello world v2\n")}, }, Comment: "second commit", User: "test", }) if err != nil { t.Fatal(err) } entries, err := r.Ancestry(LogOpts{Start: rid2, Limit: 10}) if err != nil { t.Fatal(err) } if len(entries) < 2 { t.Fatalf("Ancestry returned %d entries, want >= 2", len(entries)) } if entries[0].UUID != uuid2 { t.Errorf("first entry UUID = %q, want %q", entries[0].UUID, uuid2) } if entries[0].Comment != "second commit" { t.Errorf("first entry Comment = %q, want %q", entries[0].Comment, "second commit") } if entries[1].UUID != uuid { t.Errorf("second entry UUID = %q, want %q", entries[1].UUID, uuid) } } // TestCommitPreservesParentFiles is the regression for #30: a child // commit that supplies only a subset of the parent's tracked files must // still produce a full-tree manifest. Before the fix, the child's // manifest contained only the supplied subset and a checkout at the // child's rev silently lost every file the caller did not re-supply. func TestCommitPreservesParentFiles(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "test.fossil") r, err := Create(path, CreateOpts{User: "test"}) if err != nil { t.Fatal(err) } defer r.Close() parentRID, _, err := r.Commit(CommitOpts{ Files: []FileToCommit{ {Name: "a.txt", Content: []byte("alpha\n")}, {Name: "b.txt", Content: []byte("bravo v1\n")}, {Name: "c.txt", Content: []byte("charlie\n")}, }, Comment: "parent: a, b, c", User: "test", }) if err != nil { t.Fatalf("parent commit: %v", err) } childRID, _, err := r.Commit(CommitOpts{ ParentID: parentRID, Files: []FileToCommit{ {Name: "b.txt", Content: []byte("bravo v2\n")}, }, Comment: "child: only b modified", User: "test", }) if err != nil { t.Fatalf("child commit: %v", err) } files, err := r.ListFiles(childRID) if err != nil { t.Fatalf("ListFiles(child): %v", err) } got := map[string]string{} for _, f := range files { got[f.Name] = f.UUID } if len(got) != 3 { t.Fatalf("child manifest has %d files, want 3 (a.txt, b.txt, c.txt); got %v", len(got), got) } for _, name := range []string{"a.txt", "b.txt", "c.txt"} { if _, ok := got[name]; !ok { t.Errorf("child manifest missing %q (file tracked at parent was dropped)", name) } } // a.txt and c.txt should keep the parent's blob UUIDs (untouched). parentFiles, err := r.ListFiles(parentRID) if err != nil { t.Fatalf("ListFiles(parent): %v", err) } parentUUIDs := map[string]string{} for _, f := range parentFiles { parentUUIDs[f.Name] = f.UUID } if got["a.txt"] != parentUUIDs["a.txt"] { t.Errorf("a.txt UUID changed across commits: parent=%s child=%s", parentUUIDs["a.txt"], got["a.txt"]) } if got["c.txt"] != parentUUIDs["c.txt"] { t.Errorf("c.txt UUID changed across commits: parent=%s child=%s", parentUUIDs["c.txt"], got["c.txt"]) } // b.txt should have a NEW UUID — caller supplied new content. if got["b.txt"] == parentUUIDs["b.txt"] { t.Errorf("b.txt UUID unchanged despite new content: %s", got["b.txt"]) } } func TestListFiles(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "test.fossil") r, err := Create(path, CreateOpts{User: "test"}) if err != nil { t.Fatal(err) } defer r.Close() rid, _, err := r.Commit(CommitOpts{ Files: []FileToCommit{ {Name: "a.txt", Content: []byte("aaa\n")}, {Name: "b.txt", Content: []byte("bbb\n")}, }, Comment: "two files", User: "test", }) if err != nil { t.Fatal(err) } files, err := r.ListFiles(rid) if err != nil { t.Fatal(err) } if len(files) != 2 { t.Fatalf("ListFiles returned %d files, want 2", len(files)) } if files[0].Name != "a.txt" || files[1].Name != "b.txt" { t.Errorf("files = %v, want a.txt and b.txt", files) } }