My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/apps/servers/octopus/src/repo.rs

43 lines
1.2 KiB

use git2::{Commit, Error, Repository as Backend};
use std::collections::HashSet;
/// A structure that represents an existing bare repo on disk
pub struct Repository {
inner: Backend,
}
impl Repository {
/// Open an existing bare repo from disk storage
pub fn open(path: &'static str) -> Self {
Self {
inner: Backend::open_bare(path).unwrap(),
}
}
/// 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(|oid| {
let oid = oid.unwrap();
self.inner.find_commit(oid)
})
.collect()
}
/// Return the list of contributors
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())
}
}