Reuse project directory indexes within a revision

This commit is contained in:
gloamxun committed 2026-11-19 18:14:31 +08:00
1 parent 41af3d8d22
commit ab50ca7dad
2 files changed
+45 -5

No files matched your search

+19 -5
View File
@@ -499,6 +499,7 @@ impl InputSnapshot {
pub struct FileWorld {
config: WorldConfig,
indexes: BTreeMap<PathBuf, Arc<DirectoryIndex>>,
current_project_indexes: BTreeSet<PathBuf>,
index_failures: BTreeMap<PathBuf, DirectoryFailure>,
trace: ResourceTrace,
pinned: bool,
@@ -633,6 +634,7 @@ impl FileWorld {
Ok(Self {
config,
indexes: BTreeMap::new(),
current_project_indexes: BTreeSet::new(),
index_failures: BTreeMap::new(),
trace,
pinned: false,
@@ -672,6 +674,7 @@ impl FileWorld {
Ok(Self {
config,
indexes: BTreeMap::new(),
current_project_indexes: BTreeSet::new(),
index_failures: BTreeMap::new(),
trace,
pinned: true,
@@ -748,6 +751,7 @@ impl FileWorld {
Ok(Self {
config,
indexes: snapshot.indexes.clone(),
current_project_indexes: BTreeSet::new(),
index_failures: snapshot.index_failures.clone(),
trace,
pinned: true,
@@ -803,7 +807,9 @@ impl FileWorld {
path.display()
));
}
self.live_paths.insert(path.to_owned());
if self.live_paths.insert(path.to_owned()) && self.project.is_some() {
self.current_project_indexes.clear();
}
}
pub fn mark_generated_initial(&mut self, path: &Path) -> Result<(), String> {
if self
@@ -826,7 +832,10 @@ impl FileWorld {
let was_live = self.live_paths.remove(&resource.version.path);
if self.pinned {
if was_live || self.project.is_some() {
self.protected_paths.insert(resource.version.path.clone());
let newly_protected = self.protected_paths.insert(resource.version.path.clone());
if self.project.is_some() && (was_live || newly_protected) {
self.current_project_indexes.clear();
}
}
if was_live {
self.replay_gaps.push(format!(
@@ -1243,9 +1252,14 @@ impl FileWorld {
}
fn index(&mut self, root: &Path) -> Result<&DirectoryIndex, String> {
if let Some(project) = &self.project {
let index =
project.index(root, &self.project_paths(), self.config.max_index_entries)?;
self.indexes.insert(root.into(), Arc::new(index));
// The index tracks the logical namespace. Each candidate's live
// existence and staged bytes are still checked by probe().
if !self.current_project_indexes.contains(root) {
let index =
project.index(root, &self.project_paths(), self.config.max_index_entries)?;
self.indexes.insert(root.into(), Arc::new(index));
self.current_project_indexes.insert(root.into());
}
return Ok(&self.indexes[root]);
}
if self.pinned {