memoryd, proto, brokerd, bxctl: repeated error lines written once

Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
2026-09-25 16:41:44 -07:00
parent b98f373ead
commit 3640d32de0
5 changed files with 54 additions and 82 deletions
+23 -28
View File
@@ -236,6 +236,25 @@ fn noted(
})
}
/// Mark the entry `old` names as named: stale if `before` has no such entry, an error if it was
/// named already.
fn claim(
file: MemoryFile,
before: &[String],
named: &mut HashSet<usize>,
old: &str,
) -> Result<(), String> {
let pos = position(before, old).ok_or_else(|| stale(file))?;
if named.insert(pos) {
Ok(())
} else {
Err(format!(
"consolidate names an entry of {} twice",
file.name()
))
}
}
fn consolidate(
file: MemoryFile,
before: &[String],
@@ -249,43 +268,19 @@ fn consolidate(
let action = line.action().map_err(|e| e.to_string())?;
match action {
proto::EntryAction::Keep(old) => {
let pos = position(before, &old).ok_or_else(|| stale(file))?;
if !named.insert(pos) {
return Err(format!(
"consolidate names an entry of {} twice",
file.name()
));
}
claim(file, before, &mut named, &old)?;
after.push(old.trim().to_string());
}
proto::EntryAction::Rewrite { old, text } => {
let pos = position(before, &old).ok_or_else(|| stale(file))?;
if !named.insert(pos) {
return Err(format!(
"consolidate names an entry of {} twice",
file.name()
));
}
claim(file, before, &mut named, &old)?;
after.push(checked(&text)?);
}
proto::EntryAction::Move(old) => {
let pos = position(before, &old).ok_or_else(|| stale(file))?;
if !named.insert(pos) {
return Err(format!(
"consolidate names an entry of {} twice",
file.name()
));
}
claim(file, before, &mut named, &old)?;
out.push(note(ctx, Kind::Moved(file), old.trim()));
}
proto::EntryAction::Drop(old) => {
let pos = position(before, &old).ok_or_else(|| stale(file))?;
if !named.insert(pos) {
return Err(format!(
"consolidate names an entry of {} twice",
file.name()
));
}
claim(file, before, &mut named, &old)?;
out.push(note(ctx, Kind::Dropped(file), old.trim()));
}
proto::EntryAction::New(text) => {