Skip to content

Commit 009dda1

Browse files
authored
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
1 parent ba535fb commit 009dda1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

crates/ignore/src/dir.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,12 @@ impl Ignore {
202202
errs.maybe_push(err);
203203
igtmp.is_absolute_parent = true;
204204
igtmp.absolute_base = Some(absolute_base.clone());
205-
igtmp.has_git = if self.0.opts.git_ignore {
206-
parent.join(".git").exists()
207-
} else {
208-
false
209-
};
205+
igtmp.has_git =
206+
if self.0.opts.require_git && self.0.opts.git_ignore {
207+
parent.join(".git").exists()
208+
} else {
209+
false
210+
};
210211
ig = Ignore(Arc::new(igtmp));
211212
compiled.insert(parent.as_os_str().to_os_string(), ig.clone());
212213
}
@@ -231,7 +232,9 @@ impl Ignore {
231232

232233
/// Like add_child, but takes a full path and returns an IgnoreInner.
233234
fn add_child_path(&self, dir: &Path) -> (IgnoreInner, Option<Error>) {
234-
let git_type = if self.0.opts.git_ignore || self.0.opts.git_exclude {
235+
let git_type = if self.0.opts.require_git
236+
&& (self.0.opts.git_ignore || self.0.opts.git_exclude)
237+
{
235238
dir.join(".git").metadata().ok().map(|md| md.file_type())
236239
} else {
237240
None

0 commit comments

Comments
 (0)