diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/project/git.rs | 14 | ||||
-rw-r--r-- | src/search/entry.rs | 1 |
2 files changed, 6 insertions, 9 deletions
diff --git a/src/project/git.rs b/src/project/git.rs index 00cd000..17573c3 100644 --- a/src/project/git.rs +++ b/src/project/git.rs @@ -14,15 +14,14 @@ pub struct GitProject { impl GitProject { fn new(path_buf: PathBuf) -> Result<Self, Error> { - let latest_commit = Self::latest_commit(&path_buf).ok(); + let repo = Repository::open(&path_buf)?; Ok(Self { path_buf, - latest_commit, + latest_commit: Self::latest_commit(&repo).ok(), }) } - fn latest_commit(path_buf: &PathBuf) -> Result<Duration, Error> { - let repository = Repository::open(path_buf)?; + fn latest_commit(repository: &Repository) -> Result<Duration, Error> { let mut branches = repository.branches(Some(BranchType::Local))?; branches .try_fold(0, |latest, branch| { @@ -46,10 +45,9 @@ impl Timestamp for GitProject { type Error = Error; fn timestamp(&self) -> Result<Duration, Self::Error> { - match self.latest_commit { - Some(t) => Ok(t), - None => Self::latest_commit(&self.path_buf), - } + self.latest_commit.ok_or(Error::Git(git2::Error::from_str( + "Failed to get latest commit", + ))) } } diff --git a/src/search/entry.rs b/src/search/entry.rs index 1d885c8..778c75c 100644 --- a/src/search/entry.rs +++ b/src/search/entry.rs @@ -41,7 +41,6 @@ impl Entry { impl Iterator for Entry { type Item = ProjectItem; - #[tracing::instrument] fn next(&mut self) -> Option<Self::Item> { match self.iter.next()? { Ok(dir_entry) => self.parse_dir_entry(dir_entry), |