Compare commits

..

No commits in common. "master" and "v1.3.0" have entirely different histories.

8 changed files with 41 additions and 127 deletions

26
Cargo.lock generated
View File

@ -149,23 +149,23 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.40" version = "0.4.39"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
"js-sys", "js-sys",
"num-traits", "num-traits",
"wasm-bindgen", "wasm-bindgen",
"windows-link", "windows-targets",
] ]
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.32" version = "4.5.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83" checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@ -173,9 +173,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.32" version = "4.5.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8" checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -186,9 +186,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.5.32" version = "4.5.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@ -392,7 +392,7 @@ dependencies = [
[[package]] [[package]]
name = "git-heatmap" name = "git-heatmap"
version = "1.4.0" version = "1.3.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@ -1796,12 +1796,6 @@ dependencies = [
"windows-targets", "windows-targets",
] ]
[[package]]
name = "windows-link"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.52.0" version = "0.52.0"

View File

@ -2,8 +2,8 @@ cargo-features = ["codegen-backend"]
[package] [package]
name = "git-heatmap" name = "git-heatmap"
version = "1.4.0" version = "1.3.0"
edition = "2024" edition = "2021"
authors = ["Wynd <wyndftw@proton.me>"] authors = ["Wynd <wyndftw@proton.me>"]
description = "A simple and customizable heatmap for git repos" description = "A simple and customizable heatmap for git repos"
readme = "README.md" readme = "README.md"
@ -25,8 +25,8 @@ gix = { version = "0.70.0", default-features = false, features = [
"mailmap", "mailmap",
"parallel", "parallel",
] } ] }
clap = { version = "4.5.32", features = ["derive"] } clap = { version = "4.5.26", features = ["derive"] }
chrono = { version = "0.4.40" } chrono = { version = "0.4.39" }
itertools = { version = "0.14.0" } itertools = { version = "0.14.0" }
anyhow = { version = "1.0.95" } anyhow = { version = "1.0.95" }
rayon = { version = "1.10.0" } rayon = { version = "1.10.0" }

View File

@ -3,8 +3,8 @@ use std::sync::OnceLock;
use chrono::{Local, NaiveDate}; use chrono::{Local, NaiveDate};
use gix::ObjectId; use gix::ObjectId;
use libgitheatmap::{ use libgitheatmap::{
Commit,
heatmap::{self, Heatmap}, heatmap::{self, Heatmap},
Commit,
}; };
static COMMITS: OnceLock<Vec<Commit>> = OnceLock::new(); static COMMITS: OnceLock<Vec<Commit>> = OnceLock::new();
@ -16,13 +16,12 @@ fn main() {
let title = mockd::words::sentence(10); let title = mockd::words::sentence(10);
let author = mockd::name::full(); let author = mockd::name::full();
let email = mockd::contact::email(); let email = mockd::contact::email();
let repo = "project".to_string();
let time = mockd::datetime::date_range( let time = mockd::datetime::date_range(
"2024-01-01T00:00:00Z".to_string(), "2024-01-01T00:00:00Z".to_string(),
"2025-01-01T00:00:00Z".to_string(), "2025-01-01T00:00:00Z".to_string(),
) )
.with_timezone(&Local); .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"); COMMITS.set(commits).expect("unable to generate commits");
@ -52,7 +51,5 @@ fn heatmap_generation() {
false, false,
13, 13,
heatmap::Format::Chars, heatmap::Format::Chars,
true,
true,
); );
} }

View File

@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel = "nightly-2025-04-07" channel = "nightly-2024-12-02"

View File

@ -1,7 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use chrono::{Duration, Local}; use chrono::{Duration, Local};
use clap::{Parser, ValueHint, arg}; use clap::{arg, Parser, ValueHint};
use crate::heatmap::{ColorLogic, Format, HeatmapColors}; use crate::heatmap::{ColorLogic, Format, HeatmapColors};
@ -53,12 +53,6 @@ pub struct CliArgs {
#[arg(short, long("format"), value_enum, default_value_t = Format::Chars)] #[arg(short, long("format"), value_enum, default_value_t = Format::Chars)]
pub format: Format, 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 { fn get_since_date() -> String {

View File

@ -1,5 +1,5 @@
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::BTreeMap,
fmt::{Display, Write}, fmt::{Display, Write},
}; };
@ -7,24 +7,20 @@ use chrono::{Datelike, Duration, NaiveDate};
use clap::ValueEnum; use clap::ValueEnum;
use itertools::Itertools; use itertools::Itertools;
use crate::{Commit, DAYS, RESET, get_char, get_color, get_color_map}; use crate::{get_char, get_color, get_color_map, Commit, DAYS, RESET};
pub struct Heatmap { pub struct Heatmap {
since: NaiveDate, since: NaiveDate,
until: NaiveDate, until: NaiveDate,
commits: Vec<Commit>, commits: Vec<Commit>,
repo_commits: Vec<(String, u64)>,
highest_count: i32, highest_count: i32,
branches: usize, branches: usize,
repos: usize, repos: usize,
chunks: Vec<Chunk>, chunks: Vec<Chunk>,
format: Format, format: Format,
list_repos: bool,
list_days: bool,
} }
#[allow(clippy::too_many_arguments)]
impl Heatmap { impl Heatmap {
pub fn new( pub fn new(
since: NaiveDate, since: NaiveDate,
@ -35,33 +31,24 @@ impl Heatmap {
split_months: bool, split_months: bool,
months_per_row: u16, months_per_row: u16,
format: Format, format: Format,
list_repos: bool,
list_days: bool,
) -> Self { ) -> Self {
let mut chunks = vec![]; let mut heatmap = Self {
let mut highest_count: i32 = 0; since,
let mut grouped_commits = BTreeMap::new(); until,
let mut repo_commits_map: HashMap<String, u64> = HashMap::new(); commits,
let mut repo_commits = Vec::<(String, u64)>::new(); 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 commit_day = commit.time.date_naive();
let record = grouped_commits.entry(commit_day).or_insert(0); let record = grouped_commits.entry(commit_day).or_insert(0);
*record += 1; *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; let mut current_day = since;
@ -95,7 +82,7 @@ impl Heatmap {
chunk_idx += 1; chunk_idx += 1;
if chunk_idx > months_per_row - 1 { if chunk_idx > months_per_row - 1 {
chunks.push(chunk); heatmap.chunks.push(chunk);
chunk = Chunk::new(day_of_week); chunk = Chunk::new(day_of_week);
chunk_idx = 0; chunk_idx = 0;
} }
@ -109,8 +96,8 @@ impl Heatmap {
match value { match value {
Some(val) => { Some(val) => {
chunk.data[day_of_week as usize].push(*val); chunk.data[day_of_week as usize].push(*val);
if *val > highest_count { if *val > heatmap.highest_count {
highest_count = *val; heatmap.highest_count = *val;
} }
} }
None => { None => {
@ -123,22 +110,10 @@ impl Heatmap {
} }
if chunk_idx <= months_per_row { if chunk_idx <= months_per_row {
chunks.push(chunk); heatmap.chunks.push(chunk);
} }
Self { heatmap
since,
until,
commits,
repo_commits,
highest_count,
branches,
repos,
chunks,
format,
list_repos,
list_days,
}
} }
} }
@ -167,32 +142,11 @@ impl Display for Heatmap {
) )
.unwrap(); .unwrap();
writeln!(f, "{} {}", authors, authors_label).unwrap(); writeln!(f, "{} {}", authors, authors_label).unwrap();
writeln!(f, "{} {}", commits, commits_label).unwrap(); writeln!(f, "{} {}\n", 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];
for chunk in &self.chunks { for chunk in &self.chunks {
chunk.display(self, f); chunk.display(self, f);
writeln!(f).unwrap(); 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(); write!(f, "\nLess ").unwrap();
@ -201,13 +155,6 @@ impl Display for Heatmap {
} }
writeln!(f, " More").unwrap(); 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(()) Ok(())
} }
} }

View File

@ -11,8 +11,8 @@ use chrono::{DateTime, Duration, Local, NaiveDate, NaiveTime, TimeZone};
use clap::Parser; use clap::Parser;
use cli::CliArgs; use cli::CliArgs;
use gix::{ use gix::{
ObjectId, ThreadSafeRepository, bstr::ByteSlice, revision::walk::Sorting, bstr::ByteSlice, revision::walk::Sorting, traverse::commit::simple::CommitTimeOrder, ObjectId,
traverse::commit::simple::CommitTimeOrder, ThreadSafeRepository,
}; };
use heatmap::{ColorLogic, HeatmapColors}; use heatmap::{ColorLogic, HeatmapColors};
use itertools::Itertools; use itertools::Itertools;
@ -53,7 +53,6 @@ pub struct Commit {
id: ObjectId, id: ObjectId,
title: String, title: String,
author: Author, author: Author,
repo: String,
time: DateTime<Local>, time: DateTime<Local>,
} }
@ -63,7 +62,6 @@ impl Commit {
title: String, title: String,
author: String, author: String,
email: String, email: String,
repo: String,
time: DateTime<Local>, time: DateTime<Local>,
) -> Self { ) -> Self {
Self { Self {
@ -73,7 +71,6 @@ impl Commit {
name: author, name: author,
email, email,
}, },
repo,
time, time,
} }
} }
@ -156,16 +153,6 @@ pub fn get_commits(
for (i, repo_path) in repos.iter().enumerate() { for (i, repo_path) in repos.iter().enumerate() {
let repo = ThreadSafeRepository::open(repo_path).unwrap(); 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 branch_names = &*branches[i];
let branches = get_repo_branches(&repo, branch_names).unwrap(); let branches = get_repo_branches(&repo, branch_names).unwrap();
@ -225,7 +212,6 @@ pub fn get_commits(
id: c.id, id: c.id,
title, title,
author, author,
repo: repo_name.to_string(),
time, time,
}) })
}) })

View File

@ -16,8 +16,6 @@ fn main() -> Result<()> {
let split_months = args.split_months; let split_months = args.split_months;
let months_per_row = args.months_per_row; let months_per_row = args.months_per_row;
let format = args.format; let format = args.format;
let list_repos = args.list_repos;
let list_days = args.list_days;
let commits = libgitheatmap::get_commits(args, since, until) let commits = libgitheatmap::get_commits(args, since, until)
.with_context(|| "Could not fetch commit list")?; .with_context(|| "Could not fetch commit list")?;
@ -31,8 +29,6 @@ fn main() -> Result<()> {
split_months, split_months,
months_per_row, months_per_row,
format, format,
list_repos,
list_days,
); );
println!("{heatmap}"); println!("{heatmap}");