Refactor path ignore rule handling in Project and ServeSession

- Introduced a new method `path_ignore_rules` in the Project struct to streamline the creation of PathIgnoreRule instances.
- Updated ServeSession and snapshot middleware to utilize the new method, improving code clarity and reducing duplication.
- Removed redundant PathIgnoreRule mapping from multiple locations, enhancing maintainability.
This commit is contained in:
Joe 2026-03-06 23:12:28 -06:00
parent 89869f685d
commit 0243181731
3 changed files with 21 additions and 23 deletions

View file

@ -12,7 +12,11 @@ use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
use crate::{ use crate::{
glob::Glob, json, resolution::UnresolvedValue, snapshot::SyncRule, syncback::SyncbackRules, glob::Glob,
json,
resolution::UnresolvedValue,
snapshot::{PathIgnoreRule, SyncRule},
syncback::SyncbackRules,
}; };
/// Represents 'default' project names that act as `init` files /// Represents 'default' project names that act as `init` files
@ -334,6 +338,17 @@ impl Project {
pub fn folder_location(&self) -> &Path { pub fn folder_location(&self) -> &Path {
self.file_location.parent().unwrap() self.file_location.parent().unwrap()
} }
pub fn path_ignore_rules(&self) -> Vec<PathIgnoreRule> {
let base = self.folder_location().to_path_buf();
self.glob_ignore_paths
.iter()
.map(|glob| PathIgnoreRule {
glob: glob.clone(),
base_path: base.clone(),
})
.collect()
}
} }
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]

View file

@ -17,7 +17,7 @@ use crate::{
session_id::SessionId, session_id::SessionId,
snapshot::{ snapshot::{
apply_patch_set, compute_patch_set, AppliedPatchSet, InstanceContext, InstanceSnapshot, apply_patch_set, compute_patch_set, AppliedPatchSet, InstanceContext, InstanceSnapshot,
PatchSet, PathIgnoreRule, RojoTree, PatchSet, RojoTree,
}, },
snapshot_middleware::{is_script_relevant_path, snapshot_from_vfs, INIT_FILE_PRIORITY}, snapshot_middleware::{is_script_relevant_path, snapshot_from_vfs, INIT_FILE_PRIORITY},
}; };
@ -138,14 +138,7 @@ fn prefetch_project_files(project: &Project, sync_scripts_only: bool) -> io::Res
let folder = project.folder_location(); let folder = project.folder_location();
let ignore_rules: Vec<PathIgnoreRule> = project let ignore_rules = project.path_ignore_rules();
.glob_ignore_paths
.iter()
.map(|glob| PathIgnoreRule {
glob: glob.clone(),
base_path: folder.to_path_buf(),
})
.collect();
let mut roots: Vec<std::path::PathBuf> = Vec::new(); let mut roots: Vec<std::path::PathBuf> = Vec::new();
collect_path_roots(&project.tree, folder, &mut roots); collect_path_roots(&project.tree, folder, &mut roots);
@ -454,14 +447,7 @@ impl ServeSession {
.as_deref() .as_deref()
.and_then(crate::git::git_head_commit); .and_then(crate::git::git_head_commit);
let path_ignore_rules: Vec<PathIgnoreRule> = root_project let path_ignore_rules = root_project.path_ignore_rules();
.glob_ignore_paths
.iter()
.map(|glob| PathIgnoreRule {
glob: glob.clone(),
base_path: root_project.folder_location().to_path_buf(),
})
.collect();
log::trace!("Starting ChangeProcessor"); log::trace!("Starting ChangeProcessor");
let change_processor = ChangeProcessor::start( let change_processor = ChangeProcessor::start(

View file

@ -17,7 +17,7 @@ use crate::{
resolution::UnresolvedValue, resolution::UnresolvedValue,
snapshot::{ snapshot::{
InstanceContext, InstanceMetadata, InstanceSnapshot, InstanceWithMeta, InstigatingSource, InstanceContext, InstanceMetadata, InstanceSnapshot, InstanceWithMeta, InstigatingSource,
PathIgnoreRule, SyncRule, SyncRule,
}, },
snapshot_middleware::Middleware, snapshot_middleware::Middleware,
syncback::{ syncback::{
@ -115,10 +115,7 @@ pub fn snapshot_project(
let mut context = context.clone(); let mut context = context.clone();
context.clear_sync_rules(); context.clear_sync_rules();
let rules = project.glob_ignore_paths.iter().map(|glob| PathIgnoreRule { let rules = project.path_ignore_rules();
glob: glob.clone(),
base_path: project.folder_location().to_path_buf(),
});
let sync_rules = project.sync_rules.iter().map(|rule| SyncRule { let sync_rules = project.sync_rules.iter().map(|rule| SyncRule {
base_path: project.folder_location().to_path_buf(), base_path: project.folder_location().to_path_buf(),