Skip to content

Commit

Permalink
Merge remote-tracking branch 'gi/fix-gitignore-option'
Browse files Browse the repository at this point in the history
  • Loading branch information
lespea committed Jun 1, 2020
2 parents c44c92e + 046af5c commit 93c79be
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 236 deletions.
21 changes: 3 additions & 18 deletions src/exa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use scoped_threadpool::Pool;
use log::debug;

use crate::fs::{Dir, File};
use crate::fs::feature::ignore::IgnoreCache;
use crate::fs::feature::git::GitCache;
use crate::options::{Options, Vars};
pub use crate::options::vars;
Expand Down Expand Up @@ -45,10 +44,6 @@ pub struct Exa<'args, 'w, W: Write + 'w> {
/// This has to last the lifetime of the program, because the user might
/// want to list several directories in the same repository.
pub git: Option<GitCache>,

/// A cache of git-ignored files.
/// This lasts the lifetime of the program too, for the same reason.
pub ignore: Option<IgnoreCache>,
}

/// The “real” environment variables type.
Expand All @@ -72,15 +67,6 @@ fn git_options(options: &Options, args: &[&OsStr]) -> Option<GitCache> {
}
}

fn ignore_cache(options: &Options) -> Option<IgnoreCache> {
use crate::fs::filter::GitIgnore;

match options.filter.git_ignore {
GitIgnore::CheckAndIgnore => Some(IgnoreCache::new()),
GitIgnore::Off => None,
}
}

impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
pub fn from_args<I>(args: I, writer: &'w mut W) -> Result<Exa<'args, 'w, W>, Misfire>
where I: Iterator<Item=&'args OsString> {
Expand All @@ -96,8 +82,7 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
}

let git = git_options(&options, &args);
let ignore = ignore_cache(&options);
Exa { options, writer, args, git, ignore }
Exa { options, writer, args, git }
})
}

Expand Down Expand Up @@ -165,7 +150,7 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
}

let mut children = Vec::new();
for file in dir.files(self.options.filter.dot_filter, self.ignore.as_ref(), Some(pool)) {
for file in dir.files(self.options.filter.dot_filter, self.git.as_ref(), Some(pool)) {
match file {
Ok(file) => children.push(file),
Err((path, e)) => writeln!(stderr(), "[{}: {}]", path.display(), e)?,
Expand Down Expand Up @@ -225,7 +210,7 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
let recurse = self.options.dir_action.recurse_options();

let r = details::Render { dir, files, colours, style, opts, filter, recurse };
r.render(self.git.as_ref(), self.ignore.as_ref(), self.writer)
r.render(self.git.as_ref(), self.writer)
}

Mode::GridDetails(ref opts) => {
Expand Down
16 changes: 8 additions & 8 deletions src/fs/dir.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::fs::feature::git::GitCache;
use crate::fs::fields::GitStatus;
use std::io::{self, Result as IOResult};
use std::fs;
use std::path::{Path, PathBuf};
Expand All @@ -9,7 +11,6 @@ use scoped_threadpool::Pool;
use log::info;

use crate::fs::File;
use crate::fs::feature::ignore::IgnoreCache;


/// A **Dir** provides a cached list of the file paths in a directory that's
Expand Down Expand Up @@ -47,9 +48,7 @@ impl Dir {

/// Produce an iterator of IO results of trying to read all the files in
/// this directory.
pub fn files<'dir, 'ig>(&'dir self, dots: DotFilter, ignore: Option<&'ig IgnoreCache>, pool: Option<&mut Pool>) -> Files<'dir, 'ig> {
if let Some(i) = ignore { i.discover_underneath(&self.path); }

pub fn files<'dir, 'ig>(&'dir self, dots: DotFilter, git: Option<&'ig GitCache>, pool: Option<&mut Pool>) -> Files<'dir, 'ig> {
// File::new calls std::fs::File::metadata, which on linux calls lstat. On some
// filesystems this can be very slow, but there's no async filesystem API
// so all we can do to hide the latency is use system threads.
Expand Down Expand Up @@ -89,7 +88,7 @@ impl Dir {
dir: self,
dotfiles: dots.shows_dotfiles(),
dots: dots.dots(),
ignore,
git,
}
}

Expand Down Expand Up @@ -121,7 +120,7 @@ pub struct Files<'dir, 'ig> {
/// any files have been listed.
dots: Dots,

ignore: Option<&'ig IgnoreCache>,
git: Option<&'ig GitCache>,
}

impl<'dir, 'ig> Files<'dir, 'ig> {
Expand All @@ -142,8 +141,9 @@ impl<'dir, 'ig> Files<'dir, 'ig> {
let filename = File::filename(&path);
if !self.dotfiles && filename.starts_with('.') { continue; }

if let Some(i) = self.ignore {
if i.is_ignored(&path) { continue; }
let git_status = self.git.map(|g| g.get(path, false)).unwrap_or_default();
if git_status.unstaged == GitStatus::Ignored {
continue;
}

let target_metadata = target_metadata.map(|m| m.map_err(|e| Arc::try_unwrap(e).unwrap()));
Expand Down
198 changes: 0 additions & 198 deletions src/fs/feature/ignore.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/fs/feature/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod xattr;
pub mod ignore;

#[cfg(feature="git")] pub mod git;

Expand Down
1 change: 1 addition & 0 deletions src/fs/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub struct Time {
/// A file’s status in a Git repository. Whether a file is in a repository or
/// not is handled by the Git module, rather than having a “null” variant in
/// this enum.
#[derive(PartialEq)]
pub enum GitStatus {

/// This file hasn’t changed since the last commit.
Expand Down
6 changes: 5 additions & 1 deletion src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
use std::ffi::{OsStr, OsString};

use crate::fs::dir_action::DirAction;
use crate::fs::filter::FileFilter;
use crate::fs::filter::{FileFilter,GitIgnore};
use crate::output::{View, Mode, details, grid_details};

mod style;
Expand Down Expand Up @@ -146,6 +146,10 @@ impl Options {
/// 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 {
if self.filter.git_ignore == GitIgnore::CheckAndIgnore {
return true;
}

match self.view.mode {
Mode::Details(details::Options { table: Some(ref table), .. }) |
Mode::GridDetails(grid_details::Options { details: details::Options { table: Some(ref table), .. }, .. }) => table.columns.git,
Expand Down
Loading

0 comments on commit 93c79be

Please sign in to comment.