Artifact e20f5cbe51d0036f62dad082a9731ec66f5f879db73467a0bda55903ee874b8f:
- File
internal/checkout/update_undo.go
— part of check-in
[294a537880]
at
2026-10-19 16:10:06
on branch feat/submanifest-reader
— fix(checkout): save undo state in Update, as fossil does
Update saved no undo state, so nothing could reverse it. It now reads the file of every step that writes or removes one before writing, as fossil's update calls undo_save, and saves those files with copies of vfile and vmerge and the checked-out version in the same transaction that moves the checkout to the target. If a write fails partway the files are put back, as fossil's undo_rollback does.
Checkout.Undo and Checkout.Redo (internal and public) swap that state back and forth and keep checkout-hash naming the restored version. The undo package gains ReadFile, SaveTx and RestoreFiles, and its undo table now has fossil's schema (isExe, unique pathname, rowid order, the executable bit read from disk), so fossil undo reverses a go-libfossil update and Checkout.Undo reverses fossil update; fossil 2.28 interop tests check both. Under js/wasm, which has no undo package, Update saves nothing.
Tracked in #446 (user: [email protected], size: 1118) [annotate] [blame] [check-ins using] [more...]
//go:build !js package checkout import ( "database/sql" "github.com/danmestas/go-libfossil/internal/undo" ) // updateUndo is the undo state Update saves: the files its steps change, as // they were before. type updateUndo struct { files []undo.File } // readUpdateUndo reads the file of every step that writes or removes one, // under its name in the checkout, as fossil's update calls undo_save. func (c *Checkout) readUpdateUndo(steps []updateStep) (updateUndo, error) { var u updateUndo for _, s := range steps { switch s.action { case updateWrite, updateAddOver, updateMerge, updateRemove: default: continue } f, err := undo.ReadFile(c.env.Storage, c.dir, s.name) if err != nil { return updateUndo{}, err } u.files = append(u.files, f) } return u, nil } // save records u as the undo state within tx, before vfile moves. func (u updateUndo) save(tx *sql.Tx) error { return undo.SaveTx(tx, u.files) } // rollBackUpdate puts u's files back after an update failed partway. func (c *Checkout) rollBackUpdate(u updateUndo) error { return undo.RestoreFiles(c.env, c.dir, u.files) }