Artifact b6c075d42dc37b81f05714e697908866c89d60956acce412caa32f42d4bb082d:
- File
receipt_test.go
— part of check-in
[4add332299]
at
2026-10-18 20:30:31
on branch feat/submanifest-reader
— fix: record one rcvfrom row per receipt, as fossil does
Fossil records each arrival of content (a commit, a tag, a sync or clone, a request its server answers, an unversioned add) as one rcvfrom row, made by content_rcvid_init when the first content arrives, and points every blob and unversioned file it stores at that row. go-libfossil seeded a single row at creation and pointed every blob at rcvid 1.
db.Receipt is that row: it is made lazily on first use, with the time as a Julian day, and remade if the transaction that made it rolled back. A transaction records content under the receipt it is given, and repo.WithReceipt gives one to every transaction, bound ones included, of a commit, tag, sync, clone or served request. The client credits its local user and the peer's address, as fossil's client records g.zIpAddr; the server credits nobody until a login card names a user, then that user and the card's nonce, from the request's address. Phantoms keep rcvid 0, and an applied unversioned deletion keeps its row's rcvid, as in fossil.
A new repository no longer starts with a placeholder row; an existing one keeps it. (user: [email protected], size: 1086) [annotate] [blame] [check-ins using] [more...]
package libfossil import ( "path/filepath" "testing" "time" _ "github.com/danmestas/go-libfossil/internal/testdriver" ) // `fossil uv add` records its own receipt, credited to the local user, with // the command named where a peer's address would be. func TestUVWriteRecordsFossilsReceipt(t *testing.T) { r, err := Create(filepath.Join(t.TempDir(), "test.fossil"), CreateOpts{User: "test"}) if err != nil { t.Fatal(err) } defer r.Close() if err := r.UVWrite("a.txt", []byte("a\n"), time.Unix(1700000000, 0)); err != nil { t.Fatal(err) } var login, ip string var nonceNull bool err = r.inner.DB().QueryRow("SELECT user.login, rcvfrom.ipaddr, rcvfrom.nonce IS NULL"+ " FROM unversioned JOIN rcvfrom USING(rcvid) JOIN user ON user.uid=rcvfrom.uid"+ " WHERE name='a.txt'").Scan(&login, &ip, &nonceNull) if err != nil { t.Fatalf("receipt of a.txt: %v", err) } if login != "test" || ip != "#!fossil unversioned add" || !nonceNull { t.Fatalf("receipt = (%q, %q, nonce NULL %v), want (\"test\", \"#!fossil unversioned add\", true)", login, ip, nonceNull) } }