blob: 3dae8086b4980d31a1e12ca7ef85ac4ad9a2b5b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
use git2::{Commit, Error, Repository as Backend};
use std::collections::HashSet;
// /// Represents a repository on disk
// struct Repository {
// /// We need to be able to query libgit2 later
// fs_path: String,
// /// The project name (last path element)
// name: String,
// /// The rope path excluding the name
// path: Vec<String>,
// }
/// 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())
}
}
|