Skip to content

Commit

Permalink
ignore: if require_git is false, don't stat .git
Browse files Browse the repository at this point in the history
I've confirmed via strace that this eliminates a pile of stat calls.

PR #2052
  • Loading branch information
joshtriplett authored Nov 12, 2021
1 parent ba535fb commit 009dda1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/ignore/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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<Error>) {
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
Expand Down

0 comments on commit 009dda1

Please sign in to comment.