Skip to content

Commit

Permalink
Walk the commit tree for authors
Browse files Browse the repository at this point in the history
  • Loading branch information
sondr3 committed Oct 15, 2018
1 parent 13df37c commit 2409bb2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![forbid(unsafe_code)]
extern crate git2;

use git2::Repository;
use git2::{Commit, Repository};
use std::collections::HashMap;
use std::env;
use std::error::Error;
Expand All @@ -28,16 +28,39 @@ fn main() -> Result<(), Box<Error>> {
let curses: Vec<&str> = CURSES.lines().collect();
let path = env::current_dir()?;
let repo = Repository::open(path)?;
let mut revwalk = repo.revwalk()?;
let mut occurrences: HashMap<&str, usize> = HashMap::new();
let mut commits: Vec<Commit> = Vec::new();
for curse in &curses {
occurrences.entry(curse).or_insert(0);
}
revwalk.push_head()?;
for commit in revwalk {
let commit = repo.find_commit(commit?)?;
commits.push(commit);
}
let mut authors: Vec<Author> = find_authors(&commits);
println!("{:?}", repo.workdir());
filter_occurrences(&mut occurrences);
println!("{:#?}", occurrences);
println!("{:#?}", commits);
print!("{:#?}", authors);
Ok(())
}

fn find_authors(commits: &[Commit]) -> Vec<Author> {
let mut names: Vec<String> = Vec::new();
let mut res: Vec<Author> = Vec::new();
for commit in commits {
let name = commit.author().name().unwrap().to_string();
if !names.contains(&name) {
res.push(Author::new(name.as_str(), HashMap::new()));
}
names.push(name);
}
res
}

fn update_occurrence<'a>(word: &'a str, map: &mut HashMap<&'a str, usize>) {
map.entry(word).and_modify(|i| *i += 1);
}
Expand Down

0 comments on commit 2409bb2

Please sign in to comment.