summaryrefslogtreecommitdiffstats
path: root/src/dir.rs
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-01-28 15:49:17 +0000
committerBen S <ogham@bsago.me>2015-01-28 15:49:17 +0000
commit04b2483d1fd6230960f77c98420999b3e823242b (patch)
treeddd7aec05e65a5f0608cb3b270ab8172f03f9089 /src/dir.rs
parentf794f5eda6bfdd975ea331c437e8c744118c0f3a (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.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/dir.rs b/src/dir.rs
index 1591086..e22b092 100644
--- a/src/dir.rs
+++ b/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)),