aboutsummaryrefslogtreecommitdiff
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
parentc896fcdab70f101a6eaaa4fd6f7f03f9b1324e81 (diff)
data: adding a small wrapper around libgit2
-rw-r--r--src/main.rs15
-rw-r--r--src/pages/repo/about.rs (renamed from src/pages/repo.rs)2
-rw-r--r--src/pages/repo/mod.rs3
-rw-r--r--src/repo.rs48
4 files changed, 32 insertions, 36 deletions
diff --git a/src/main.rs b/src/main.rs
index ed633e0..c0b0f61 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,20 +14,5 @@ fn main() -> std::io::Result<()> {
// .bind("127.0.0.1:8080")?
// .run()?;
- let r = repo::Repo::new("./testrepo");
- let mut walker = r.inner.revwalk().unwrap();
- walker.push_head().unwrap();
- dbg!(walker
- .into_iter()
- .map(|oid| {
- let oid = oid.unwrap();
- r.inner
- .find_commit(oid)
- .unwrap()
- .message()
- .unwrap()
- .to_owned()
- })
- .collect::<Vec<_>>());
Ok(())
}
diff --git a/src/pages/repo.rs b/src/pages/repo/about.rs
index aa66839..adfa46e 100644
--- a/src/pages/repo.rs
+++ b/src/pages/repo/about.rs
@@ -1,4 +1,4 @@
-//! The view that renders a repository
+//! The "repository/about" subpage
use actix_web::{web, HttpRequest, HttpResponse, Result};
use askama::Template;
diff --git a/src/pages/repo/mod.rs b/src/pages/repo/mod.rs
new file mode 100644
index 0000000..c339350
--- /dev/null
+++ b/src/pages/repo/mod.rs
@@ -0,0 +1,3 @@
+//! The repository page subtree
+
+pub mod about;
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())
}
}