refactor: drop dependency to the ignore crate (#493)

This commit is contained in:
Alexandre Pasmantier 2025-05-01 23:05:05 +02:00 committed by Alex Pasmantier
parent f887a2390e
commit cc27b5ec6b
3 changed files with 0 additions and 52 deletions

17
Cargo.lock generated
View File

@ -1001,22 +1001,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "ignore"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b"
dependencies = [
"crossbeam-deque",
"globset",
"log",
"memchr",
"regex-automata 0.4.9",
"same-file",
"walkdir",
"winapi-util",
]
[[package]]
name = "image"
version = "0.25.6"
@ -2225,7 +2209,6 @@ dependencies = [
"directories",
"gag",
"human-panic",
"ignore",
"image",
"nom",
"nucleo",

View File

@ -48,7 +48,6 @@ ratatui = { version = "0.29", features = ["serde", "macros"] }
better-panic = "0.3"
signal-hook = "0.3"
human-panic = "2.0"
ignore = "0.4"
strum = { version = "0.26", features = ["derive"] }
regex = "1.11"
parking_lot = "0.12"

View File

@ -5,10 +5,8 @@ use std::io::BufRead;
use std::io::BufReader;
use std::io::Read;
use std::path::Path;
use std::path::PathBuf;
use std::sync::OnceLock;
use ignore::{overrides::Override, types::TypesBuilder, WalkBuilder};
use tracing::{debug, warn};
use crate::utils::strings::{
@ -67,38 +65,6 @@ pub fn get_default_num_threads() -> usize {
*DEFAULT_NUM_THREADS.get_or_init(default_num_threads)
}
pub fn walk_builder(
path: &Path,
n_threads: usize,
overrides: Option<Override>,
ignore_paths: Option<Vec<PathBuf>>,
) -> WalkBuilder {
let mut builder = WalkBuilder::new(path);
// ft-based filtering
let mut types_builder = TypesBuilder::new();
types_builder.add_defaults();
builder.types(types_builder.build().unwrap());
// ignore paths
if let Some(paths) = ignore_paths {
builder.filter_entry(move |e| {
let path = e.path();
if paths.iter().any(|p| path.starts_with(p)) {
debug!("Ignoring path: {:?}", path);
return false;
}
true
});
}
builder.threads(n_threads);
if let Some(ov) = overrides {
builder.overrides(ov);
}
builder
}
pub fn get_file_size(path: &Path) -> Option<u64> {
std::fs::metadata(path).ok().map(|m| m.len())
}