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.
This commit is contained in:
Benjamin Sago 2017-09-01 22:52:13 +01:00
parent f3c7fa500f
commit 558b13880b
3 changed files with 9 additions and 8 deletions

View File

@ -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();

View File

@ -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 {

View File

@ -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 {