Help us shape the future of Go! Take the 2026 Go Developer Survey

undo

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package undo saves, restores, and redoes checkout state in a Fossil .fslckout database.

The undo state machine uses a vvar entry "undo_available":

0 — nothing saved
1 — undo available (Save was called)
2 — redo available (Undo was called)

Only one level of undo/redo is kept; each Save replaces any previous state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RestoreFiles added in v0.14.0

func RestoreFiles(disk vfile.Disk, dir string, files []File) error

RestoreFiles puts files back through disk as ReadFile found them, as fossil's undo_rollback does for an operation that failed partway.

func Save

func Save(ckout *sql.DB, disk vfile.Disk, dir string, pathnames []string) error

Save snapshots the current checkout state so it can be undone later. If pathnames is non-nil and non-empty, only those vfile entries are saved; otherwise all vfile rows are included. Files are read through disk, as fossil's undo_save reads them: a symlink seen as itself is saved as one.

A saved vfile row keeps its mtime only while it vouches for the saved content, that is while the file's mtime still matches it, so Undo can record a restored file's new mtime on it; otherwise it is saved with 0.

func SaveTx added in v0.14.0

func SaveTx(tx *sql.Tx, files []File) error

SaveTx replaces the undo state within tx, as fossil's undo_begin and undo_save do: copies of vfile and vmerge as they are now, files (each pathname once, the first kept), and the checked-out version, with undo marked available. The caller runs it before the operation's own changes to vfile, in the same transaction.

Types

type Action added in v0.14.0

type Action int

Action is what Undo or Redo did to a working file.

const (
	Restored Action = iota + 1 // overwrote the file; fossil prints UNDO or REDO
	Created                    // wrote a file that was not there; fossil prints NEW
	Deleted                    // removed the file; fossil prints DELETE
)

func (Action) String added in v0.14.0

func (a Action) String() string

String names a.

type Change added in v0.14.0

type Change struct {
	Pathname string
	Action   Action
}

Change is one working file Undo or Redo changed, for a caller to report as fossil's undo prints it.

func Redo

func Redo(ckout *sql.DB, disk vfile.Disk, dir string) ([]Change, error)

Redo reverses the most recent Undo, returning the working files it changed as Undo does. It requires undo_available == 2.

func Swap added in v0.14.0

func Swap(
	ckout *sql.DB, disk vfile.Disk, dir string, redo bool, hashOf func(int64) (string, error),
) ([]Change, error)

Swap is Undo, or Redo when redo is set, that also keeps vvar's checkout-hash naming the checked-out version, as fossil's db_set_checkout does: hashOf returns the hash of a check-in rid.

func Undo

func Undo(ckout *sql.DB, disk vfile.Disk, dir string) ([]Change, error)

Undo restores the state saved by the most recent Save call, returning the working files it changed in the order it changed them, fossil's order. It requires undo_available == 1.

type File added in v0.14.0

type File struct {
	// contains filtered or unexported fields
}

File is a working file as fossil's undo_save records it: its content, or that it does not exist, read before an operation changes it.

func ReadFile added in v0.14.0

func ReadFile(disk vfile.Disk, dir, pathname string) (File, error)

ReadFile reads the working file pathname, relative to the checkout directory dir, through disk for SaveTx. A missing file is recorded as missing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL