glit_core/
log.rs

1use crate::repo::Committers;
2use git2::{Oid, Sort};
3use indicatif::{ProgressBar, ProgressStyle};
4use std::{path::PathBuf, thread};
5
6pub struct Log {}
7
8impl Log {
9    pub fn build(path: PathBuf, repo_name: String, branch: String) -> Committers {
10        let repo = git2::Repository::open_bare(path.as_path()).unwrap();
11        let mut revwalk = repo.revwalk().unwrap();
12        revwalk.set_sorting(Sort::TIME).unwrap();
13
14        let mut repo_data = Committers::new();
15        revwalk.push_head().unwrap();
16
17        log::info!(
18            "[{:?}][{:?}] Build log by revwalking ...",
19            thread::current().id(),
20            &path
21        );
22
23        let walk: Vec<Oid> = revwalk.map(|id| id.unwrap()).collect();
24
25        let pb = ProgressBar::new(walk.len().try_into().unwrap());
26        pb.set_message(format!("[{}][{}]", repo_name, branch));
27        let style = ProgressStyle::with_template(
28            "🏃 REVWALKING {msg}{spinner:.green}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
29        )
30        .unwrap()
31        .progress_chars("#>-");
32
33        pb.set_style(style);
34
35        for (i, commit_id) in walk.into_iter().enumerate() {
36            pb.set_position(i.try_into().unwrap());
37            repo_data.update(&repo, commit_id);
38        }
39
40        pb.finish_with_message(format!("[{} ✅][{} ✅]", repo_name, branch));
41        pb.finish_and_clear();
42        repo_data
43    }
44}