aboutsummaryrefslogtreecommitdiff
path: root/src/repo.rs
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2019-12-29 16:34:39 +0100
committerKatharina Fey <kookie@spacekookie.de>2019-12-29 16:34:39 +0100
commit8b38bdd1478baf6fd53b9a8a53eb3a183c59b781 (patch)
treecd0a417fd84befa98b660310a248f4f5172463bc /src/repo.rs
parentc896fcdab70f101a6eaaa4fd6f7f03f9b1324e81 (diff)
data: adding a small wrapper around libgit2
Diffstat (limited to '')
-rw-r--r--src/repo.rs48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/repo.rs b/src/repo.rs
index 0056575..3dae808 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -1,5 +1,5 @@
-use git2::Repository;
-
+use git2::{Commit, Error, Repository as Backend};
+use std::collections::HashSet;
// /// Represents a repository on disk
// struct Repository {
@@ -12,34 +12,42 @@ use git2::Repository;
// }
/// A structure that represents an existing bare repo on disk
-pub struct Repo {
- pub inner: Repository,
+pub struct Repository {
+ inner: Backend,
}
-impl Repo {
- pub fn new(path: &'static str) -> Self {
+impl Repository {
+ /// Open an existing bare repo from disk storage
+ pub fn open(path: &'static str) -> Self {
Self {
- inner: Repository::open_bare(path).unwrap(),
+ inner: Backend::open_bare(path).unwrap(),
}
}
- /// Returns a list of commit hashes for a project
- pub fn commits(&self) -> Vec<String> {
- vec!["f6ca929", "43fb776", "1a0fa2f".into()]
+ /// Get all commits on head
+ pub fn head<'a>(&'a self) -> Result<Vec<Commit<'a>>, Error> {
+ let mut walker = self.inner.revwalk().unwrap();
+ walker.push_head()?;
+ walker
.into_iter()
- .map(String::from)
+ .map(|oid| {
+ let oid = oid.unwrap();
+ self.inner.find_commit(oid)
+ })
.collect()
}
/// Return the list of contributors
- fn contributors(&self) -> Vec<String> {
- vec![
- "Katharina Fey <kookie@spacekookie.de",
- "Robin Example <robin@example.com",
- "Ferris <ferris@the.crab>",
- ]
- .into_iter()
- .map(String::from)
- .collect()
+ fn contributors(&self) -> Result<Vec<String>, Error> {
+ let head = self.head()?;
+ Ok(head
+ .iter()
+ .map(|c| c.author())
+ .fold(HashSet::new(), |mut set, author| {
+ set.insert(author.name().unwrap().to_owned());
+ set
+ })
+ .into_iter()
+ .collect())
}
}