3e72c29a7ba3

keep diff --session and load --checkpoint on the line (3.0.12)

time
2026-09-23 22:03 UTC · 2 weeks ago
machine
koh2
agent
claude-opus-5-5
session
koh 3 review fixes
parent
c3643bd4833e
4 files VERSION+1 −1src/history/history.v+9 −18src/history/history_test.v+26 −0v.mod+1 −1
VERSION+1 −1
@@ -1 +1 @@1-3.0.111+3.0.12

view file

src/history/history.v+9 −18
@@ -166,29 +166,20 @@166166 	return error('no save on the line belongs to a session')167167 }168168 169-// session_saves returns every save in a session, oldest first.169+// session_saves returns the line's saves in a session, oldest first. A save170+// replayed away by a combine is off the line, and its copy stands for it.170171 pub fn session_saves(store &storage.Store, name string) ![]Save {171-	mut stmt := store.db.prepare('${select_save} WHERE session = ? ORDER BY created_at, id')!172-	defer {173-		stmt.finalize()174-	}175-	stmt.bind_text(1, name)!176-	mut saves := []Save{}177-	for stmt.step()! {178-		saves << read_save(stmt)179-	}172+	mut saves := line(store)!.filter(it.session == name)173+	saves.reverse_in_place()180174 	return saves181175 }182176 177+// latest_checkpoint is the newest checkpoint on the line.183178 pub fn latest_checkpoint(store &storage.Store) ?Save {184-	mut stmt := store.db.prepare('${select_save} WHERE is_checkpoint = 1 ORDER BY created_at DESC, id DESC LIMIT 1') or {185-		return none186-	}187-	defer {188-		stmt.finalize()189-	}190-	if stmt.step() or { return none } {191-		return read_save(stmt)179+	for save in line(store) or { return none } {180+		if save.is_checkpoint {181+			return save182+		}192183 	}193184 	return none194185 }

view file

src/history/history_test.v+26 −0
@@ -121,3 +121,29 @@121121 		assert err.msg().contains('no save starts with')122122 	}123123 }124+125+// A combine leaves the replayed-away originals in history but off the line.126+// `load --checkpoint` and `diff --session` answer about the line.127+fn test_checkpoint_and_session_lookups_stay_on_the_line() {128+	mut store, dir := temp_repo('on_line')!129+	defer {130+		store.close()131+		os.rmdir_all(dir) or {}132+	}133+	write_file(dir, 'a.txt', 'one\n')!134+	kept := commit_worktree(store, dir, snapshot.Ignore{}, SaveInput{135+		message:       'on the line'136+		session:       'work'137+		is_checkpoint: true138+	})!139+	write_file(dir, 'a.txt', 'two\n')!140+	commit_worktree(store, dir, snapshot.Ignore{}, SaveInput{141+		message:       'replayed away later'142+		session:       'work'143+		is_checkpoint: true144+	})!145+	// What a combine does to the line: head moves elsewhere, the save stays.146+	set_head(store, kept.id)!147+	assert latest_checkpoint(store)?.id == kept.id148+	assert session_saves(store, 'work')!.map(it.id) == [kept.id]149+}

view file

v.mod+1 −1
@@ -1,6 +1,6 @@11 Module {22 	name: 'koh3'3-	version: '3.0.11'3+	version: '3.0.12'44 	description: 'One SQLite file per repo, one line of history.'55 	license: 'MIT'66 }

view file