Просмотр исходного кода

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.
Ben S 10 лет назад
Родитель
Сommit
d547c3f5d7
4 измененных файлов с 20 добавлено и 5 удалено
  1. 2 2
      src/dir.rs
  2. 1 1
      src/file.rs
  3. 1 1
      src/main.rs
  4. 16 1
      src/options.rs

+ 2 - 2
src/dir.rs

@@ -23,11 +23,11 @@ impl Dir {
     /// Create a new Dir object filled with all the files in the directory
     /// Create a new Dir object filled with all the files in the directory
     /// pointed to by the given path. Fails if the directory can't be read, or
     /// pointed to by the given path. Fails if the directory can't be read, or
     /// isn't actually a directory.
     /// isn't actually a directory.
-    pub fn readdir(path: &Path) -> io::Result<Dir> {
+    pub fn readdir(path: &Path, git: bool) -> io::Result<Dir> {
         fs::read_dir(path).map(|dir_obj| Dir {
         fs::read_dir(path).map(|dir_obj| Dir {
             contents: dir_obj.map(|entry| entry.unwrap().path()).collect(),
             contents: dir_obj.map(|entry| entry.unwrap().path()).collect(),
             path: path.to_path_buf(),
             path: path.to_path_buf(),
-            git: Git::scan(path).ok(),
+            git: if git { Git::scan(path).ok() } else { None },
         })
         })
     }
     }
 
 

+ 1 - 1
src/file.rs

@@ -82,7 +82,7 @@ impl<'dir> File<'dir> {
         // that represents the current File as a directory, if it is a
         // that represents the current File as a directory, if it is a
         // directory. This is used for the --tree option.
         // directory. This is used for the --tree option.
         let this = if recurse && metadata.is_dir() {
         let this = if recurse && metadata.is_dir() {
-            Dir::readdir(path).ok()
+            Dir::readdir(path, false).ok()
         }
         }
         else {
         else {
             None
             None

+ 1 - 1
src/main.rs

@@ -144,7 +144,7 @@ impl<'dir> Exa<'dir> {
                 print!("\n");
                 print!("\n");
             }
             }
 
 
-            match Dir::readdir(&dir_path) {
+            match Dir::readdir(&dir_path, self.options.should_scan_for_git()) {
                 Ok(ref dir) => {
                 Ok(ref dir) => {
                     let mut files = dir.files(false);
                     let mut files = dir.files(false);
                     self.options.transform_files(&mut files);
                     self.options.transform_files(&mut files);

+ 16 - 1
src/options.rs

@@ -110,6 +110,17 @@ impl Options {
     pub fn transform_files(&self, files: &mut Vec<File>) {
     pub fn transform_files(&self, files: &mut Vec<File>) {
         self.filter.transform_files(files)
         self.filter.transform_files(files)
     }
     }
+
+    /// Whether the View specified in this set of options includes a Git
+    /// status column. It's only worth trying to discover a repository if the
+    /// results will end up being displayed.
+    pub fn should_scan_for_git(&self) -> bool {
+        match self.view {
+            View::Details(Details { columns: Some(cols), .. }) => cols.should_scan_for_git(),
+            View::GridDetails(GridDetails { details: Details { columns: Some(cols), .. }, .. }) => cols.should_scan_for_git(),
+            _ => false,
+        }
+    }
 }
 }
 
 
 
 
@@ -572,6 +583,10 @@ impl Columns {
         })
         })
     }
     }
 
 
+    pub fn should_scan_for_git(&self) -> bool {
+        self.git
+    }
+
     pub fn for_dir(&self, dir: Option<&Dir>) -> Vec<Column> {
     pub fn for_dir(&self, dir: Option<&Dir>) -> Vec<Column> {
         let mut columns = vec![];
         let mut columns = vec![];
 
 
@@ -611,7 +626,7 @@ impl Columns {
 
 
         if cfg!(feature="git") {
         if cfg!(feature="git") {
             if let Some(d) = dir {
             if let Some(d) = dir {
-                if self.git && d.has_git_repo() {
+                if self.should_scan_for_git() && d.has_git_repo() {
                     columns.push(GitStatus);
                     columns.push(GitStatus);
                 }
                 }
             }
             }