mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-25 01:46:02 +00:00
Compare vectors, not strings
This is good for two reasons: 1) shorter code! 2) it won't fail if any of the filenames aren't valid UTF-8.
This commit is contained in:
parent
f794f5eda6
commit
04b2483d1f
14
src/dir.rs
14
src/dir.rs
@ -72,7 +72,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)>,
|
||||
statuses: Vec<(Vec<u8>, git2::Status)>,
|
||||
}
|
||||
|
||||
#[cfg(feature="git")]
|
||||
@ -82,16 +82,16 @@ impl Git {
|
||||
/// 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));
|
||||
|
||||
Ok(Git { statuses: statuses.iter().map(|e| (e.path().unwrap().to_string(), e.status())).collect() })
|
||||
let statuses = try!(repo.statuses(None)).iter()
|
||||
.map(|e| (e.path_bytes().to_vec(), e.status()))
|
||||
.collect();
|
||||
Ok(Git { statuses: statuses })
|
||||
}
|
||||
|
||||
/// Get the status for the file at the given path, if present.
|
||||
fn status(&self, path: &Path) -> String {
|
||||
let status = self.statuses.iter()
|
||||
.find(|p| p.0 == path.as_str().unwrap());
|
||||
|
||||
.find(|p| p.0 == path.as_vec());
|
||||
match status {
|
||||
Some(&(_, s)) => format!("{}{}", Git::index_status(s), Git::working_tree_status(s)),
|
||||
None => GREY.paint("--").to_string(),
|
||||
@ -103,7 +103,7 @@ impl Git {
|
||||
/// directories, which don't really have an 'official' status.
|
||||
fn dir_status(&self, dir: &Path) -> String {
|
||||
let status = self.statuses.iter()
|
||||
.filter(|p| p.0.starts_with(dir.as_str().unwrap()))
|
||||
.filter(|p| p.0.starts_with(dir.as_vec()))
|
||||
.fold(git2::Status::empty(), |a, b| a | b.1);
|
||||
match status {
|
||||
s => format!("{}{}", Git::index_status(s), Git::working_tree_status(s)),
|
||||
|
Loading…
Reference in New Issue
Block a user