Explorar el Código

Don’t pass Dirs to the Table

A Table now doesn’t need to know about (or even import) Dir, because we can just not pass the Git reference in if it shouldn’t be using it.
Benjamin Sago hace 8 años
padre
commit
558b13880b
Se han modificado 3 ficheros con 9 adiciones y 8 borrados
  1. 3 2
      src/output/details.rs
  2. 3 2
      src/output/grid_details.rs
  3. 3 4
      src/output/table.rs

+ 3 - 2
src/output/details.rs

@@ -140,11 +140,12 @@ impl<'a> AsRef<File<'a>> for Egg<'a> {
 
 
 impl<'a> Render<'a> {
-    pub fn render<W: Write>(self, git: Option<&'a GitCache>, w: &mut W) -> IOResult<()> {
+    pub fn render<W: Write>(self, mut git: Option<&'a GitCache>, w: &mut W) -> IOResult<()> {
         let mut rows = Vec::new();
 
         if let Some(ref table) = self.opts.table {
-            let mut table = Table::new(&table, self.dir, git, &self.colours);
+        	if self.dir.is_none() { git = None }
+            let mut table = Table::new(&table, git, &self.colours);
 
             if self.opts.header {
                 let header = table.header_row();

+ 3 - 2
src/output/grid_details.rs

@@ -167,8 +167,9 @@ impl<'a> Render<'a> {
         None
     }
 
-    fn make_table<'t>(&'a self, options: &'a TableOptions, git: Option<&'a GitCache>, drender: &DetailsRender) -> (Table<'a>, Vec<DetailsRow>) {
-        let mut table = Table::new(options, self.dir, git, self.colours);
+    fn make_table<'t>(&'a self, options: &'a TableOptions, mut git: Option<&'a GitCache>, drender: &DetailsRender) -> (Table<'a>, Vec<DetailsRow>) {
+        if self.dir.is_none() { git = None }
+        let mut table = Table::new(options, git, self.colours);
         let mut rows = Vec::new();
 
         if self.details.header {

+ 3 - 4
src/output/table.rs

@@ -13,7 +13,7 @@ use users::UsersCache;
 use style::Colours;
 use output::cell::TextCell;
 use output::time::TimeFormat;
-use fs::{File, Dir, fields as f};
+use fs::{File, fields as f};
 use fs::feature::git::GitCache;
 
 
@@ -284,9 +284,8 @@ pub struct Row {
 }
 
 impl<'a, 'f> Table<'a> {
-    pub fn new(options: &'a Options, dir: Option<&'a Dir>, git: Option<&'a GitCache>, colours: &'a Colours) -> Table<'a> {
-        let has_git = if let (Some(g), Some(d)) = (git, dir) { g.has_anything_for(&d.path) } else { false };
-        let columns = options.extra_columns.collect(has_git);
+    pub fn new(options: &'a Options, git: Option<&'a GitCache>, colours: &'a Colours) -> Table<'a> {
+        let columns = options.extra_columns.collect(git.is_some());
         let widths = TableWidths::zero(columns.len());
 
         Table {