Compare commits
No commits in common. "e608cd99583126166d662fc94141ac66dac80a5e" and "437e3689d5e6d7cc408ad0caf8e219a6f663d48e" have entirely different histories.
e608cd9958
...
437e3689d5
|
@ -16,13 +16,12 @@ fn main() {
|
|||
let title = mockd::words::sentence(10);
|
||||
let author = mockd::name::full();
|
||||
let email = mockd::contact::email();
|
||||
let repo = "project".to_string();
|
||||
let time = mockd::datetime::date_range(
|
||||
"2024-01-01T00:00:00Z".to_string(),
|
||||
"2025-01-01T00:00:00Z".to_string(),
|
||||
)
|
||||
.with_timezone(&Local);
|
||||
commits.push(Commit::new(id, title, author, email, repo, time));
|
||||
commits.push(Commit::new(id, title, author, email, time));
|
||||
}
|
||||
|
||||
COMMITS.set(commits).expect("unable to generate commits");
|
||||
|
@ -52,7 +51,5 @@ fn heatmap_generation() {
|
|||
false,
|
||||
13,
|
||||
heatmap::Format::Chars,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2025-04-07"
|
||||
channel = "nightly-2025-03-20"
|
||||
|
|
|
@ -53,12 +53,6 @@ pub struct CliArgs {
|
|||
|
||||
#[arg(short, long("format"), value_enum, default_value_t = Format::Chars)]
|
||||
pub format: Format,
|
||||
|
||||
#[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 {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
collections::BTreeMap,
|
||||
fmt::{Display, Write},
|
||||
};
|
||||
|
||||
|
@ -13,18 +13,14 @@ pub struct Heatmap {
|
|||
since: NaiveDate,
|
||||
until: NaiveDate,
|
||||
commits: Vec<Commit>,
|
||||
repo_commits: Vec<(String, u64)>,
|
||||
highest_count: i32,
|
||||
branches: usize,
|
||||
repos: usize,
|
||||
chunks: Vec<Chunk>,
|
||||
|
||||
format: Format,
|
||||
list_repos: bool,
|
||||
list_days: bool,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
impl Heatmap {
|
||||
pub fn new(
|
||||
since: NaiveDate,
|
||||
|
@ -35,33 +31,24 @@ impl Heatmap {
|
|||
split_months: bool,
|
||||
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, u64> = HashMap::new();
|
||||
let mut repo_commits = Vec::<(String, u64)>::new();
|
||||
let mut heatmap = Self {
|
||||
since,
|
||||
until,
|
||||
commits,
|
||||
highest_count: 0,
|
||||
branches,
|
||||
repos,
|
||||
chunks: vec![],
|
||||
format,
|
||||
};
|
||||
|
||||
for commit in &commits {
|
||||
let mut grouped_commits = BTreeMap::new();
|
||||
|
||||
for commit in &heatmap.commits {
|
||||
let commit_day = commit.time.date_naive();
|
||||
let record = grouped_commits.entry(commit_day).or_insert(0);
|
||||
*record += 1;
|
||||
|
||||
if list_repos {
|
||||
let commits = repo_commits_map.entry(commit.repo.clone()).or_insert(0);
|
||||
*commits += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if list_repos {
|
||||
repo_commits.extend(
|
||||
repo_commits_map
|
||||
.into_iter()
|
||||
.sorted_by(|c1, c2| c2.1.cmp(&c1.1))
|
||||
.map(|e| (e.0, e.1)),
|
||||
);
|
||||
}
|
||||
|
||||
let mut current_day = since;
|
||||
|
@ -95,7 +82,7 @@ impl Heatmap {
|
|||
chunk_idx += 1;
|
||||
|
||||
if chunk_idx > months_per_row - 1 {
|
||||
chunks.push(chunk);
|
||||
heatmap.chunks.push(chunk);
|
||||
chunk = Chunk::new(day_of_week);
|
||||
chunk_idx = 0;
|
||||
}
|
||||
|
@ -109,8 +96,8 @@ impl Heatmap {
|
|||
match value {
|
||||
Some(val) => {
|
||||
chunk.data[day_of_week as usize].push(*val);
|
||||
if *val > highest_count {
|
||||
highest_count = *val;
|
||||
if *val > heatmap.highest_count {
|
||||
heatmap.highest_count = *val;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
@ -123,22 +110,10 @@ impl Heatmap {
|
|||
}
|
||||
|
||||
if chunk_idx <= months_per_row {
|
||||
chunks.push(chunk);
|
||||
heatmap.chunks.push(chunk);
|
||||
}
|
||||
|
||||
Self {
|
||||
since,
|
||||
until,
|
||||
commits,
|
||||
repo_commits,
|
||||
highest_count,
|
||||
branches,
|
||||
repos,
|
||||
chunks,
|
||||
format,
|
||||
list_repos,
|
||||
list_days,
|
||||
}
|
||||
heatmap
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,32 +142,11 @@ impl Display for Heatmap {
|
|||
)
|
||||
.unwrap();
|
||||
writeln!(f, "{} {}", authors, authors_label).unwrap();
|
||||
writeln!(f, "{} {}", commits, commits_label).unwrap();
|
||||
|
||||
if self.list_repos {
|
||||
for (repo, repo_commits) in &self.repo_commits {
|
||||
let commits_label = if *repo_commits == 1 {
|
||||
"commit"
|
||||
}
|
||||
else {
|
||||
"commits"
|
||||
};
|
||||
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];
|
||||
writeln!(f, "{} {}\n", commits, commits_label).unwrap();
|
||||
|
||||
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();
|
||||
|
@ -201,13 +155,6 @@ 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(())
|
||||
}
|
||||
}
|
||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -53,7 +53,6 @@ pub struct Commit {
|
|||
id: ObjectId,
|
||||
title: String,
|
||||
author: Author,
|
||||
repo: String,
|
||||
time: DateTime<Local>,
|
||||
}
|
||||
|
||||
|
@ -63,7 +62,6 @@ impl Commit {
|
|||
title: String,
|
||||
author: String,
|
||||
email: String,
|
||||
repo: String,
|
||||
time: DateTime<Local>,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -73,7 +71,6 @@ impl Commit {
|
|||
name: author,
|
||||
email,
|
||||
},
|
||||
repo,
|
||||
time,
|
||||
}
|
||||
}
|
||||
|
@ -156,16 +153,6 @@ pub fn get_commits(
|
|||
for (i, repo_path) in repos.iter().enumerate() {
|
||||
let repo = ThreadSafeRepository::open(repo_path).unwrap();
|
||||
|
||||
let repo_name = match repo_path.parent() {
|
||||
Some(parent) => parent.file_name(),
|
||||
None => repo_path.file_name(),
|
||||
};
|
||||
let repo_name = repo_name
|
||||
.iter()
|
||||
.filter_map(|r| r.to_str())
|
||||
.next()
|
||||
.unwrap_or("unknown");
|
||||
|
||||
let branch_names = &*branches[i];
|
||||
let branches = get_repo_branches(&repo, branch_names).unwrap();
|
||||
|
||||
|
@ -225,7 +212,6 @@ pub fn get_commits(
|
|||
id: c.id,
|
||||
title,
|
||||
author,
|
||||
repo: repo_name.to_string(),
|
||||
time,
|
||||
})
|
||||
})
|
||||
|
|
|
@ -16,8 +16,6 @@ fn main() -> Result<()> {
|
|||
let split_months = args.split_months;
|
||||
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,8 +29,6 @@ fn main() -> Result<()> {
|
|||
split_months,
|
||||
months_per_row,
|
||||
format,
|
||||
list_repos,
|
||||
list_days,
|
||||
);
|
||||
|
||||
println!("{heatmap}");
|
||||
|
|
Loading…
Reference in New Issue