Option to list amount of commits per day
parent
fe02a4bf0d
commit
e608cd9958
|
@ -53,5 +53,6 @@ fn heatmap_generation() {
|
|||
13,
|
||||
heatmap::Format::Chars,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -56,6 +56,9 @@ pub struct CliArgs {
|
|||
|
||||
#[arg(long("list-repos"), default_value_t = false)]
|
||||
pub list_repos: bool,
|
||||
|
||||
#[arg(long("list-days"), default_value_t = false)]
|
||||
pub list_days: bool,
|
||||
}
|
||||
|
||||
fn get_since_date() -> String {
|
||||
|
|
|
@ -13,7 +13,7 @@ pub struct Heatmap {
|
|||
since: NaiveDate,
|
||||
until: NaiveDate,
|
||||
commits: Vec<Commit>,
|
||||
repo_commits: Vec<(String, Vec<Commit>)>,
|
||||
repo_commits: Vec<(String, u64)>,
|
||||
highest_count: i32,
|
||||
branches: usize,
|
||||
repos: usize,
|
||||
|
@ -21,6 +21,7 @@ pub struct Heatmap {
|
|||
|
||||
format: Format,
|
||||
list_repos: bool,
|
||||
list_days: bool,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
@ -35,12 +36,13 @@ impl Heatmap {
|
|||
months_per_row: u16,
|
||||
format: Format,
|
||||
list_repos: bool,
|
||||
list_days: bool,
|
||||
) -> Self {
|
||||
let mut chunks = vec![];
|
||||
let mut highest_count: i32 = 0;
|
||||
let mut grouped_commits = BTreeMap::new();
|
||||
let mut repo_commits_map: HashMap<String, Vec<Commit>> = HashMap::new();
|
||||
let mut repo_commits = Vec::<(String, Vec<Commit>)>::new();
|
||||
let mut repo_commits_map: HashMap<String, u64> = HashMap::new();
|
||||
let mut repo_commits = Vec::<(String, u64)>::new();
|
||||
|
||||
for commit in &commits {
|
||||
let commit_day = commit.time.date_naive();
|
||||
|
@ -48,13 +50,8 @@ impl Heatmap {
|
|||
*record += 1;
|
||||
|
||||
if list_repos {
|
||||
if repo_commits_map.contains_key(&commit.repo) {
|
||||
let list = repo_commits_map.get_mut(&commit.repo).unwrap();
|
||||
list.push(commit.clone());
|
||||
}
|
||||
else {
|
||||
repo_commits_map.insert(commit.repo.clone(), vec![commit.clone()]);
|
||||
}
|
||||
let commits = repo_commits_map.entry(commit.repo.clone()).or_insert(0);
|
||||
*commits += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +59,7 @@ impl Heatmap {
|
|||
repo_commits.extend(
|
||||
repo_commits_map
|
||||
.into_iter()
|
||||
.sorted_by(|c1, c2| c2.1.len().cmp(&c1.1.len()))
|
||||
.sorted_by(|c1, c2| c2.1.cmp(&c1.1))
|
||||
.map(|e| (e.0, e.1)),
|
||||
);
|
||||
}
|
||||
|
@ -140,6 +137,7 @@ impl Heatmap {
|
|||
chunks,
|
||||
format,
|
||||
list_repos,
|
||||
list_days,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,21 +170,29 @@ impl Display for Heatmap {
|
|||
writeln!(f, "{} {}", commits, commits_label).unwrap();
|
||||
|
||||
if self.list_repos {
|
||||
for (repo, commits_vec) in &self.repo_commits {
|
||||
let commits_label = if commits_vec.len() == 1 {
|
||||
for (repo, repo_commits) in &self.repo_commits {
|
||||
let commits_label = if *repo_commits == 1 {
|
||||
"commit"
|
||||
}
|
||||
else {
|
||||
"commits"
|
||||
};
|
||||
writeln!(f, " {}: {} {}", repo, commits_vec.len(), commits_label).unwrap();
|
||||
writeln!(f, " {}: {} {}", repo, repo_commits, commits_label).unwrap();
|
||||
}
|
||||
}
|
||||
writeln!(f).unwrap();
|
||||
|
||||
let mut per_day_commits: [i32; 7] = [0, 0, 0, 0, 0, 0, 0];
|
||||
|
||||
for chunk in &self.chunks {
|
||||
chunk.display(self, f);
|
||||
writeln!(f).unwrap();
|
||||
if self.list_days {
|
||||
per_day_commits
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
.for_each(|(i, v)| *v += chunk.data[i].iter().sum::<i32>());
|
||||
}
|
||||
}
|
||||
|
||||
write!(f, "\nLess ").unwrap();
|
||||
|
@ -195,6 +201,13 @@ impl Display for Heatmap {
|
|||
}
|
||||
writeln!(f, " More").unwrap();
|
||||
|
||||
if self.list_days {
|
||||
writeln!(f).unwrap();
|
||||
for day in 0..DAYS.len() {
|
||||
writeln!(f, "{}: {}", DAYS[day], per_day_commits[day]).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ fn main() -> Result<()> {
|
|||
let months_per_row = args.months_per_row;
|
||||
let format = args.format;
|
||||
let list_repos = args.list_repos;
|
||||
let list_days = args.list_days;
|
||||
|
||||
let commits = libgitheatmap::get_commits(args, since, until)
|
||||
.with_context(|| "Could not fetch commit list")?;
|
||||
|
@ -31,6 +32,7 @@ fn main() -> Result<()> {
|
|||
months_per_row,
|
||||
format,
|
||||
list_repos,
|
||||
list_days,
|
||||
);
|
||||
|
||||
println!("{heatmap}");
|
||||
|
|
Loading…
Reference in New Issue