global gitignore handling in the background scanner

This commit is contained in:
Cole Miller 2025-07-17 18:34:44 -04:00
parent 8b0203e177
commit 3119d0d06e
5 changed files with 167 additions and 61 deletions

View file

@ -4,6 +4,9 @@ use std::{ffi::OsStr, path::Path, sync::Arc};
#[derive(Debug)]
pub enum IgnoreStack {
None,
Global {
ignore: Arc<Gitignore>,
},
Some {
abs_base_path: Arc<Path>,
ignore: Arc<Gitignore>,
@ -21,6 +24,10 @@ impl IgnoreStack {
Arc::new(Self::All)
}
pub fn global(ignore: Arc<Gitignore>) -> Arc<Self> {
Arc::new(Self::Global { ignore })
}
pub fn append(self: Arc<Self>, abs_base_path: Arc<Path>, ignore: Arc<Gitignore>) -> Arc<Self> {
match self.as_ref() {
IgnoreStack::All => self,
@ -40,6 +47,11 @@ impl IgnoreStack {
match self {
Self::None => false,
Self::All => true,
Self::Global { ignore } => match ignore.matched(abs_path, is_dir) {
ignore::Match::None => false,
ignore::Match::Ignore(_) => true,
ignore::Match::Whitelist(_) => false,
},
Self::Some {
abs_base_path,
ignore,