Code and logging fix-ups

This commit is contained in:
Benjamin Sago 2017-08-28 18:40:52 +01:00
parent cfc05eef00
commit 62075fe984

View File

@ -15,19 +15,6 @@ pub struct GitRepo {
workdir: PathBuf,
}
impl GitRepo {
fn discover(path: &Path) -> Option<GitRepo> {
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<PathBuf> for GitCache {
fn from_iter<I: IntoIterator<Item=PathBuf>>(iter: I) -> Self {
@ -48,6 +35,19 @@ impl FromIterator<PathBuf> for GitCache {
}
}
impl GitRepo {
fn discover(path: &Path) -> Option<GitRepo> {
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<Git> {
let repo = match self.repos[index] {
@ -55,9 +55,13 @@ impl GitCache {
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();