Add more filtering logging and spans

This commit is contained in:
Félix Saparelli 2022-01-15 23:46:06 +13:00
parent 1ce238949e
commit 58d47f78e1
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
4 changed files with 15 additions and 7 deletions

View File

@ -165,7 +165,8 @@ impl TaggedFilterer {
let gc = self.glob_compiled.borrow();
if let Some(igs) = gc.as_ref() {
trace!("checking against compiled Glob filters");
let _span = trace_span!("checking_compiled_filters", compiled=%"Glob")
.entered();
match if path.strip_prefix(&self.origin).is_ok() {
trace!("checking against path or parents");
igs.matched_path_or_any_parents(path, is_dir)
@ -193,7 +194,9 @@ impl TaggedFilterer {
let ngc = self.not_glob_compiled.borrow();
if let Some(ngs) = ngc.as_ref() {
trace!("checking against compiled NotGlob filters");
let _span =
trace_span!("checking_compiled_filters", compiled=%"NotGlob")
.entered();
match if path.strip_prefix(&self.origin).is_ok() {
trace!("checking against path or parents");
ngs.matched_path_or_any_parents(path, is_dir)
@ -248,7 +251,7 @@ impl TaggedFilterer {
trace!(filters=%tag_filters.len(), "got some filters to check still");
for filter in &tag_filters {
trace!(?filter, "checking filter againt tag");
let _span = trace_span!("checking filter against tag", ?filter).entered();
if let Some(app) = self.match_tag(filter, tag)? {
if filter.negate {
if app {

View File

@ -8,7 +8,7 @@ use futures::{pin_mut, Stream, StreamExt};
use tokio::fs::{metadata, read_dir};
use tracing::{trace, trace_span};
use crate::{project::ProjectType, paths::PATH_SEPARATOR};
use crate::{paths::PATH_SEPARATOR, project::ProjectType};
/// An ignore file.
///

View File

@ -34,6 +34,10 @@ pub struct IgnoreFilterer {
impl IgnoreFilterer {
/// Read ignore files from disk and load them for filtering.
pub async fn new(origin: impl AsRef<Path>, files: &[IgnoreFile]) -> Result<Self, RuntimeError> {
let origin = origin.as_ref();
let _span = trace_span!("build_filterer", ?origin);
trace!(files=%files.len(), "loading file contents");
let (files_contents, errors): (Vec<_>, Vec<_>) = files
.iter()
.map(|file| async move {
@ -58,12 +62,13 @@ impl IgnoreFilterer {
let errors: Vec<RuntimeError> = errors.into_iter().flatten().collect();
if !errors.is_empty() {
trace!("found {} errors", errors.len());
return Err(RuntimeError::Set(errors));
}
// TODO: different parser/adapter for non-git-syntax ignore files?
let origin = origin.as_ref();
trace!(files=%files_contents.len(), "building ignore list");
let mut builder = GitignoreBuilder::new(origin);
for (file, content) in files_contents.into_iter().flatten() {
let _span = trace_span!("loading ignore file", ?file).entered();
@ -210,12 +215,11 @@ impl Filterer for IgnoreFilterer {
let mut pass = true;
for (path, file_type) in event.paths() {
let _span = trace_span!("path", ?path).entered();
let _span = trace_span!("checking_against_compiled", ?path, ?file_type).entered();
let is_dir = file_type
.map(|t| matches!(t, FileType::Dir))
.unwrap_or(false);
trace!("checking against compiled ignore files");
match if path.strip_prefix(&self.origin).is_ok() {
trace!("checking against path or parents");
self.compiled.matched_path_or_any_parents(path, is_dir)

View File

@ -243,6 +243,7 @@ pub async fn globset_igfilt(origin: &str, ignore_files: &[IgnoreFile]) -> Globse
pub async fn ignore_filt(origin: &str, ignore_files: &[IgnoreFile]) -> IgnoreFilterer {
tracing_init();
let origin = dunce::canonicalize(".").unwrap().join(origin);
IgnoreFilterer::new(origin, ignore_files)
.await
.expect("making filterer")