From 009dda1488ac6a01725b3e49ec9b81a1edf8036d Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 12 Nov 2021 14:37:05 +0100 Subject: ignore: if require_git is false, don't stat .git I've confirmed via strace that this eliminates a pile of stat calls. PR #2052 --- crates/ignore/src/dir.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/ignore/src/dir.rs b/crates/ignore/src/dir.rs index 09414e9a..2577665d 100644 --- a/crates/ignore/src/dir.rs +++ b/crates/ignore/src/dir.rs @@ -202,11 +202,12 @@ impl Ignore { errs.maybe_push(err); igtmp.is_absolute_parent = true; igtmp.absolute_base = Some(absolute_base.clone()); - igtmp.has_git = if self.0.opts.git_ignore { - parent.join(".git").exists() - } else { - false - }; + igtmp.has_git = + if self.0.opts.require_git && self.0.opts.git_ignore { + parent.join(".git").exists() + } else { + false + }; ig = Ignore(Arc::new(igtmp)); compiled.insert(parent.as_os_str().to_os_string(), ig.clone()); } @@ -231,7 +232,9 @@ impl Ignore { /// Like add_child, but takes a full path and returns an IgnoreInner. fn add_child_path(&self, dir: &Path) -> (IgnoreInner, Option) { - let git_type = if self.0.opts.git_ignore || self.0.opts.git_exclude { + let git_type = if self.0.opts.require_git + && (self.0.opts.git_ignore || self.0.opts.git_exclude) + { dir.join(".git").metadata().ok().map(|md| md.file_type()) } else { None -- cgit v1.2.3