Skip to content

Commit d547c3f

Browse files
committed
Fix bug where Git repos were always queried
This is very slow (see #28) at the moment, so there's an option to switch off repo discovery. However, they were still always being queried. Now, if there's no Git option in the flags, it won't try to discover a repo.
1 parent e1f4ea9 commit d547c3f

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ impl Dir {
2323
/// Create a new Dir object filled with all the files in the directory
2424
/// pointed to by the given path. Fails if the directory can't be read, or
2525
/// isn't actually a directory.
26-
pub fn readdir(path: &Path) -> io::Result<Dir> {
26+
pub fn readdir(path: &Path, git: bool) -> io::Result<Dir> {
2727
fs::read_dir(path).map(|dir_obj| Dir {
2828
contents: dir_obj.map(|entry| entry.unwrap().path()).collect(),
2929
path: path.to_path_buf(),
30-
git: Git::scan(path).ok(),
30+
git: if git { Git::scan(path).ok() } else { None },
3131
})
3232
}
3333

src/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'dir> File<'dir> {
8282
// that represents the current File as a directory, if it is a
8383
// directory. This is used for the --tree option.
8484
let this = if recurse && metadata.is_dir() {
85-
Dir::readdir(path).ok()
85+
Dir::readdir(path, false).ok()
8686
}
8787
else {
8888
None

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'dir> Exa<'dir> {
144144
print!("\n");
145145
}
146146

147-
match Dir::readdir(&dir_path) {
147+
match Dir::readdir(&dir_path, self.options.should_scan_for_git()) {
148148
Ok(ref dir) => {
149149
let mut files = dir.files(false);
150150
self.options.transform_files(&mut files);

src/options.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ impl Options {
110110
pub fn transform_files(&self, files: &mut Vec<File>) {
111111
self.filter.transform_files(files)
112112
}
113+
114+
/// Whether the View specified in this set of options includes a Git
115+
/// status column. It's only worth trying to discover a repository if the
116+
/// results will end up being displayed.
117+
pub fn should_scan_for_git(&self) -> bool {
118+
match self.view {
119+
View::Details(Details { columns: Some(cols), .. }) => cols.should_scan_for_git(),
120+
View::GridDetails(GridDetails { details: Details { columns: Some(cols), .. }, .. }) => cols.should_scan_for_git(),
121+
_ => false,
122+
}
123+
}
113124
}
114125

115126

@@ -572,6 +583,10 @@ impl Columns {
572583
})
573584
}
574585

586+
pub fn should_scan_for_git(&self) -> bool {
587+
self.git
588+
}
589+
575590
pub fn for_dir(&self, dir: Option<&Dir>) -> Vec<Column> {
576591
let mut columns = vec![];
577592

@@ -611,7 +626,7 @@ impl Columns {
611626

612627
if cfg!(feature="git") {
613628
if let Some(d) = dir {
614-
if self.git && d.has_git_repo() {
629+
if self.should_scan_for_git() && d.has_git_repo() {
615630
columns.push(GitStatus);
616631
}
617632
}

0 commit comments

Comments
 (0)