From 62075fe984a78acd052ea8f2cb2b5293d17786d7 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Mon, 28 Aug 2017 18:40:52 +0100 Subject: [PATCH] Code and logging fix-ups --- src/fs/feature/git.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/fs/feature/git.rs b/src/fs/feature/git.rs index 011605d..768ddc8 100644 --- a/src/fs/feature/git.rs +++ b/src/fs/feature/git.rs @@ -15,19 +15,6 @@ pub struct GitRepo { workdir: PathBuf, } -impl GitRepo { - fn discover(path: &Path) -> Option { - info!("Searching for Git repository above {:?}", path); - if let Ok(repo) = git2::Repository::discover(&path) { - if let Some(workdir) = repo.workdir().map(|wd| wd.to_path_buf()) { - return Some(GitRepo { repo, workdir }); - } - } - - None - } -} - use std::iter::FromIterator; impl FromIterator for GitCache { fn from_iter>(iter: I) -> Self { @@ -36,7 +23,7 @@ impl FromIterator for GitCache { for path in iter { if repos.contains_key(&path) { - debug!("Skipping {:?} because we already queried it", path); + debug!("Skipping {:?} because we already queried it", path); } else { let repo = GitRepo::discover(&path); @@ -48,16 +35,33 @@ impl FromIterator for GitCache { } } +impl GitRepo { + fn discover(path: &Path) -> Option { + info!("Searching for Git repository above {:?}", path); + if let Ok(repo) = git2::Repository::discover(&path) { + if let Some(workdir) = repo.workdir().map(|wd| wd.to_path_buf()) { + return Some(GitRepo { repo, workdir }); + } + } + + None + } +} + impl GitCache { pub fn get(&self, index: &Path) -> Option { let repo = match self.repos[index] { Some(ref r) => r, - None => return None, + None => return None, }; + info!("Getting Git statuses for repo with workdir {:?}", &repo.workdir); let iter = match repo.repo.statuses(None) { Ok(es) => es, - Err(_) => return None, + Err(e) => { + error!("Error looking up Git statuses: {:?}", e); + return None; + } }; let mut statuses = Vec::new();