diff options
author | Ben S <ogham@bsago.me> | 2015-01-28 15:49:17 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-01-28 15:49:17 +0000 |
commit | 04b2483d1fd6230960f77c98420999b3e823242b (patch) | |
tree | ddd7aec05e65a5f0608cb3b270ab8172f03f9089 /src/dir.rs | |
parent | f794f5eda6bfdd975ea331c437e8c744118c0f3a (diff) |
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.
Diffstat (limited to 'src/dir.rs')
-rw-r--r-- | src/dir.rs | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -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)), |