Ver Fonte

Don't even show the column without the feature

Ben S há 11 anos atrás
pai
commit
1d0cc329eb
2 ficheiros alterados com 13 adições e 4 exclusões
  1. 9 3
      src/dir.rs
  2. 4 1
      src/options.rs

+ 9 - 3
src/dir.rs

@@ -25,7 +25,7 @@ impl Dir {
         fs::readdir(&path).map(|paths| Dir {
             contents: paths,
             path: path.clone(),
-            git: Git::new(&path).ok(),
+            git: Git::scan(&path).ok(),
         })
     }
 
@@ -68,6 +68,7 @@ impl Dir {
     }
 }
 
+/// Container of Git statuses for all the files in this folder's Git repository.
 #[cfg(feature="git")]
 struct Git {
     statuses: Vec<(String, git2::Status)>,
@@ -75,7 +76,10 @@ struct Git {
 
 #[cfg(feature="git")]
 impl Git {
-    fn new(path: &Path) -> Result<Git, git2::Error> {
+
+    /// Discover a Git repository on or above this directory, scanning it for
+    /// the files' statuses if one is found.
+    fn scan(path: &Path) -> Result<Git, git2::Error> {
         let repo = try!(git2::Repository::discover(path));
         let statuses = try!(repo.statuses(None));
 
@@ -121,11 +125,13 @@ struct Git;
 
 #[cfg(not(feature="git"))]
 impl Git {
-    fn new(_: &Path) -> Result<Git, ()> {
+    fn scan(_: &Path) -> Result<Git, ()> {
+        // Don't do anything without Git support
         Err(())
     }
 
     fn status(&self, _: &Path) -> String {
+        // The Err above means that this should never happen
         panic!("Tried to access a Git repo without Git support!");
     }
 }

+ 4 - 1
src/options.rs

@@ -265,7 +265,10 @@ fn columns(matches: &getopts::Matches) -> Result<Vec<Column>, Misfire> {
         columns.push(Group);
     }
 
-    columns.push(GitStatus);
+    if cfg!(feature="git") {
+        columns.push(GitStatus);
+    }
+
     columns.push(FileName);
     Ok(columns)
 }