From f55fa110a25e9350d1b15d9d8b96d9c67c273891 Mon Sep 17 00:00:00 2001 From: Chris Busillo Date: Tue, 2 Jun 2026 10:22:00 -0400 Subject: [PATCH] Avoid creating review dirs for ledger reads --- code-rs/core/src/review_coord.rs | 23 +++++++++++++++++++++++ code-rs/core/src/review_store.rs | 10 ++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/code-rs/core/src/review_coord.rs b/code-rs/core/src/review_coord.rs index e703aa0fc70..3a8ed52035d 100644 --- a/code-rs/core/src/review_coord.rs +++ b/code-rs/core/src/review_coord.rs @@ -29,6 +29,13 @@ fn state_dir() -> std::io::Result { Ok(dir) } +fn state_dir_path() -> std::io::Result { + let mut dir = crate::config::find_code_home()?; + dir.push("state"); + dir.push("review"); + Ok(dir) +} + fn scoped_dir(scope: Option<&Path>) -> std::io::Result { let mut dir = state_dir()?; if let Some(scope) = scope { @@ -42,10 +49,26 @@ fn scoped_dir(scope: Option<&Path>) -> std::io::Result { Ok(dir) } +fn scoped_dir_path(scope: Option<&Path>) -> std::io::Result { + let mut dir = state_dir_path()?; + if let Some(scope) = scope { + let normalized_scope = scope + .canonicalize() + .unwrap_or_else(|_| scope.to_path_buf()); + let key = crc32fast::hash(normalized_scope.to_string_lossy().as_bytes()); + dir.push(format!("repo-{key:08x}")); + } + Ok(dir) +} + pub fn scoped_review_state_dir(scope: &Path) -> std::io::Result { scoped_dir(Some(scope)) } +pub fn scoped_review_state_dir_path(scope: &Path) -> std::io::Result { + scoped_dir_path(Some(scope)) +} + fn epoch_path(scope: Option<&Path>) -> std::io::Result { let mut dir = scoped_dir(scope)?; dir.push(EPOCH_FILENAME); diff --git a/code-rs/core/src/review_store.rs b/code-rs/core/src/review_store.rs index f684646f95e..3515cc66fcc 100644 --- a/code-rs/core/src/review_store.rs +++ b/code-rs/core/src/review_store.rs @@ -1,5 +1,6 @@ use crate::protocol::ReviewOutputEvent; use crate::review_coord::scoped_review_state_dir; +use crate::review_coord::scoped_review_state_dir_path; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::fs; @@ -255,7 +256,7 @@ impl AutoReviewRunStore { } pub fn open_existing(scope: &Path) -> io::Result> { - let root = auto_review_dir(scope)?; + let root = auto_review_dir_path(scope)?; if !root.exists() { return Ok(None); } @@ -412,6 +413,10 @@ pub fn auto_review_dir(scope: &Path) -> io::Result { Ok(scoped_review_state_dir(scope)?.join(AUTO_REVIEW_DIR)) } +pub fn auto_review_dir_path(scope: &Path) -> io::Result { + Ok(scoped_review_state_dir_path(scope)?.join(AUTO_REVIEW_DIR)) +} + fn read_runs_file(path: &Path) -> io::Result> { if !path.exists() { return Ok(BTreeMap::new()); @@ -1068,7 +1073,8 @@ mod tests { let store = AutoReviewRunStore::open_existing(repo.path()).unwrap(); assert!(store.is_none()); - assert!(!auto_review_dir(repo.path()).unwrap().exists()); + assert!(!auto_review_dir_path(repo.path()).unwrap().exists()); + assert!(!code_home.path().join("state").join("review").exists()); } #[test]