aboutsummaryrefslogtreecommitdiffstats
path: root/src/search
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-04-28 17:32:24 -0500
committerToby Vincent <tobyv13@gmail.com>2023-04-28 17:32:24 -0500
commit589cd987217755e1da7acbc304c373a75a9f7db5 (patch)
tree2730a697e4f7b2f779fcd96b0452719cc67f36e3 /src/search
parenta98b50667bc6a11e4b8be464969adc14601e9e78 (diff)
refactor: simplify logic and clean up dep.
Diffstat (limited to 'src/search')
-rw-r--r--src/search/entry.rs40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/search/entry.rs b/src/search/entry.rs
index 16dcd8b..efd287b 100644
--- a/src/search/entry.rs
+++ b/src/search/entry.rs
@@ -1,23 +1,33 @@
use std::path::PathBuf;
use ignore::{Walk, WalkBuilder};
-use tracing::error;
+use tracing::{debug, error};
-use crate::project::{path::PathMatcher, ProjectItem, ProjectParser, ProjectParserGroup};
+use crate::{
+ config::Filters,
+ project::{path::PathMatcher, Project, ProjectParserGroup},
+};
-use super::Filters;
-
-pub struct SearchEntry {
+pub struct SearchPath {
+ path_buf: PathBuf,
parsers: ProjectParserGroup,
iter: Walk,
}
-impl SearchEntry {
+impl std::fmt::Debug for SearchPath {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("SearchPath")
+ .field("path_buf", &self.path_buf)
+ .finish()
+ }
+}
+
+impl SearchPath {
pub fn new(path_buf: PathBuf, config: &Filters) -> Self {
let mut parsers = ProjectParserGroup::new();
if config.all {
- parsers.push(Box::new(PathMatcher::All(path_buf.to_owned())))
+ parsers.push(Box::new(PathMatcher::All))
}
if let Some(s) = config.pattern.as_ref() {
@@ -29,21 +39,29 @@ impl SearchEntry {
parsers.push(Box::new(crate::project::git::GitMatcher));
};
- let iter = WalkBuilder::new(path_buf)
+ let iter = WalkBuilder::new(&path_buf)
.standard_filters(true)
.max_depth(config.max_depth)
.hidden(!config.hidden)
.build();
- Self { parsers, iter }
+ Self {
+ path_buf,
+ parsers,
+ iter,
+ }
}
}
-impl Iterator for SearchEntry {
- type Item = ProjectItem;
+impl Iterator for SearchPath {
+ type Item = Project;
fn next(&mut self) -> Option<Self::Item> {
match self.iter.next()? {
+ Ok(dir_entry) if dir_entry.path() == self.path_buf => {
+ debug!("Ignoring parent directory");
+ None
+ }
Ok(dir_entry) => self.parsers.parse(dir_entry.into_path()),
Err(err) => {
error!(%err, "Ignoring errored path");