From 2a7452c3fd83000f239755825f38246f8537b6cc Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 15 Sep 2026 00:33:47 +0200 Subject: a permanently deleted file's steps do not keep a run partly undone --- internal/journal/read.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'internal/journal/read.go') diff --git a/internal/journal/read.go b/internal/journal/read.go index 438e6ba..5a1de04 100644 --- a/internal/journal/read.go +++ b/internal/journal/read.go @@ -230,6 +230,12 @@ func Runs(path string, n int) ([]Run, error) { order := make([]string, 0) byID := make(map[string]*Run) pendingUndo := make(map[string]string) // undo run ID -> the run ID it claims to undo + // A file whose chain ended in a permanent delete is never undone, so its + // reversible steps do not count toward what a run took (plan 11 review + // L8). + type fileOf struct{ run, dir, file string } + reversibleOf := map[fileOf]int{} + deletedFile := map[fileOf]bool{} for _, line := range lines { e, ok := parseLine(line) @@ -247,6 +253,12 @@ func Runs(path string, n int) ([]Run, error) { } if e.Status == "ok" { r.Counts[e.Action]++ + if _, ok := reversible[e.Action]; ok { + reversibleOf[fileOf{e.Run, e.Dir, e.File}]++ + } + if e.Action == "delete" { + deletedFile[fileOf{e.Run, e.Dir, e.File}] = true + } } if e.Action == "run-start" { if orig, ok := strings.CutPrefix(e.Detail, undoOfPrefix); ok && orig != "" { @@ -285,8 +297,10 @@ func Runs(path string, n int) ([]Run, error) { r.UndoOf = pendingUndo[r.ID] if r.Undone { took := 0 - for action := range reversible { - took += r.Counts[action] + for f, n := range reversibleOf { + if f.run == r.ID && !deletedFile[f] { + took += n + } } r.PartlyUndone = reversed[r.ID] < took } -- cgit v1.3