Artifact 5e1530b5b9d960c17b0894f5f00217b75b451571e0e528a730f101e4e1f715ff:
- File
cli/repo_revert.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 1457) [annotate] [blame] [check-ins using]
package cli import "fmt" // RepoRevertCmd undoes staging changes in the checkout. type RepoRevertCmd struct { Files []string `arg:"" optional:"" help:"Files to revert (default: all)"` Dir string `short:"d" help:"Checkout directory" default:"."` } func (c *RepoRevertCmd) Run(g *Globals) error { ckout, err := openCheckout(c.Dir) if err != nil { return err } defer ckout.Close() vid, err := checkoutVid(ckout) if err != nil { return err } if len(c.Files) == 0 { result, err := ckout.Exec("UPDATE vfile SET chnged=0, deleted=0, origname=NULL WHERE vid=? AND (chnged=1 OR deleted=1)", vid) if err != nil { return err } affected, _ := result.RowsAffected() removed, err := ckout.Exec("DELETE FROM vfile WHERE vid=? AND rid=0", vid) if err != nil { return err } removedCount, _ := removed.RowsAffected() fmt.Printf("reverted %d files, removed %d staged additions\n", affected, removedCount) } else { for _, name := range c.Files { var id, rid int64 err := ckout.QueryRow("SELECT id, rid FROM vfile WHERE pathname=? AND vid=?", name, vid).Scan(&id, &rid) if err != nil { return fmt.Errorf("%s: not tracked in checkout", name) } if rid == 0 { ckout.Exec("DELETE FROM vfile WHERE id=?", id) fmt.Printf("UNSTAGED %s\n", name) } else { ckout.Exec("UPDATE vfile SET chnged=0, deleted=0, origname=NULL WHERE id=?", id) fmt.Printf("REVERTED %s\n", name) } } } return nil }