Fix review findings in the regex engine, search count and journal v2

- PCRE2: compile with the ANYCRLF newline convention and DOLLAR_ENDONLY,
  as ECMAScript reads '.' and '$'. With PCRE2's default (LF only) '.'
  matched the CR of a CRLF line, so regex replace-all deleted CRs.
- Replacement $0 is the whole match, two digits are read greedily and a
  group the pattern lacks expands to nothing, as std::regex_replace
  (libstdc++) does; these cases are now compared in the tests.
- Plain search visits overlapping matches going forward too, and counts
  them, as the backward search found them ('aa' in 'aaa' read 2/1).
- The recovery prompt's replayed content is used on 'y' only if the
  journal is unchanged since; otherwise it is replayed again.
- A version 1 journal continued after recovery is rewritten as a
  compacted version 2 journal when it needs a chunked checkpoint,
  instead of receiving records an older kte would skip. (The version is
  read through a separate descriptor: the journal fd is write-only.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
Claude
2026-09-24 09:16:04 -07:00
committed by Kyle Isom
parent e782d24e32
commit 41e28a8ab7
9 changed files with 184 additions and 31 deletions
+14 -2
View File
@@ -397,6 +397,7 @@ Editor::CancelRecoveryPrompt()
pending_recovery_replay_err_.clear();
std::string().swap(pending_recovery_content_);
pending_recovery_valid_bytes_ = 0;
pending_recovery_swap_size_ = 0;
pending_recovery_have_content_ = false;
}
@@ -413,6 +414,7 @@ Editor::ResolveRecoveryPrompt(const bool yes)
std::string content = std::move(pending_recovery_content_);
const bool have_content = pending_recovery_have_content_;
std::uint64_t valid_bytes = pending_recovery_valid_bytes_;
const std::uint64_t swap_size_then = pending_recovery_swap_size_;
CancelRecoveryPrompt();
std::string err;
@@ -427,8 +429,13 @@ Editor::ResolveRecoveryPrompt(const bool yes)
SetStatus("Recovery failed: no buffer");
return false;
}
if (have_content) {
// The prompt already replayed the journal; install that.
std::uint64_t swap_size_now = 0;
try {
swap_size_now = std::filesystem::file_size(swp);
} catch (...) {
}
if (have_content && swap_size_now == swap_size_then) {
// The prompt already replayed the journal (unchanged since); install that.
b->replace_all_bytes(content);
std::string().swap(content);
} else {
@@ -607,6 +614,11 @@ Editor::process_pending_opens_()
pending_recovery_content_ = std::move(rec);
pending_recovery_valid_bytes_ = valid;
pending_recovery_have_content_ = true;
try {
pending_recovery_swap_size_ = std::filesystem::file_size(swp);
} catch (...) {
pending_recovery_have_content_ = false; // replay on "y"
}
StartPrompt(PromptKind::Confirm, "Recover", "");
SetStatus("Recover swap edits for " + req.path + "? (y/n, C-g cancel)");
return opened_any;