Compare commits

..

2 Commits

7 changed files with 135 additions and 735 deletions

799
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ cargo-features = ["codegen-backend"]
[package] [package]
name = "git-heatmap" name = "git-heatmap"
version = "1.0.3" version = "1.1.0"
edition = "2021" 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"
@ -16,11 +16,11 @@ license = "MIT"
unsafe_code = { level = "forbid" } unsafe_code = { level = "forbid" }
[dependencies] [dependencies]
gix = { version = "0.64.0" } gix = { version = "0.66.0", default-features = false, features = ["mailmap"] }
clap = { version = "4.5.13", features = ["derive"] } clap = { version = "4.5.20", features = ["derive"] }
chrono = { version = "0.4.38" } chrono = { version = "0.4.38" }
itertools = { version = "0.13.0" } itertools = { version = "0.13.0" }
anyhow = { version = "1.0.86" } anyhow = { version = "1.0.89" }
[profile.dev] [profile.dev]
codegen-backend = "cranelift" codegen-backend = "cranelift"

View File

@ -65,6 +65,11 @@ $ git-heatmap --split-months
# the amount of commits in that day # the amount of commits in that day
$ git-heatmap --counting by-amount $ git-heatmap --counting by-amount
# by default the format uses characters to represent days and colors them based on how many commits
# that day has, using the numbers format replaces those characters with the actual number of commits
# maxed at 99
$ git-heatmap --format numbers
# filter by one or multiple authors (respecting the .mailmap settings) # filter by one or multiple authors (respecting the .mailmap settings)
# without an -a flag all authors will be checked # without an -a flag all authors will be checked
$ git-heatmap -a "username" -a "other" $ git-heatmap -a "username" -a "other"

View File

@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel= "nightly" channel = "nightly"

View File

@ -3,7 +3,7 @@ use std::path::PathBuf;
use chrono::{Duration, Local}; use chrono::{Duration, Local};
use clap::{arg, Parser, ValueHint}; use clap::{arg, Parser, ValueHint};
use crate::heatmap::{ColorLogic, HeatmapColors}; use crate::heatmap::{ColorLogic, Format, HeatmapColors};
#[derive(Clone, Debug, Parser, PartialEq, Eq)] #[derive(Clone, Debug, Parser, PartialEq, Eq)]
#[command(version, about, author, long_about = None)] #[command(version, about, author, long_about = None)]
@ -43,6 +43,9 @@ pub struct CliArgs {
#[arg(long("counting"), value_enum, default_value_t = ColorLogic::ByWeight)] #[arg(long("counting"), value_enum, default_value_t = ColorLogic::ByWeight)]
pub counting: ColorLogic, pub counting: ColorLogic,
#[arg(short, long("format"), value_enum, default_value_t = Format::Chars)]
pub format: Format,
} }
fn get_since_date() -> String { fn get_since_date() -> String {

View File

@ -14,6 +14,8 @@ pub struct Heatmap {
months: Vec<(usize, String)>, months: Vec<(usize, String)>,
highest_count: i32, highest_count: i32,
repos: usize, repos: usize,
format: Format,
} }
impl Heatmap { impl Heatmap {
@ -23,6 +25,7 @@ impl Heatmap {
repos: usize, repos: usize,
commits: Vec<Commit>, commits: Vec<Commit>,
split_months: bool, split_months: bool,
format: Format,
) -> Self { ) -> Self {
let mut heatmap = Self { let mut heatmap = Self {
data: [vec![], vec![], vec![], vec![], vec![], vec![], vec![]], data: [vec![], vec![], vec![], vec![], vec![], vec![], vec![]],
@ -32,6 +35,7 @@ impl Heatmap {
months: vec![], months: vec![],
highest_count: 0, highest_count: 0,
repos, repos,
format,
}; };
let mut grouped_commits = BTreeMap::new(); let mut grouped_commits = BTreeMap::new();
@ -95,9 +99,15 @@ impl Heatmap {
let mut row = " ".to_string(); let mut row = " ".to_string();
let mut last_index = 0; let mut last_index = 0;
let mul = match self.format {
Format::Chars => 2,
Format::Numbers => 3,
};
for (index, month) in &self.months { for (index, month) in &self.months {
let range_size = (index * 2).saturating_sub(last_index * 2).saturating_sub(3); let range_size = (index * mul)
.saturating_sub(last_index * mul)
.saturating_sub(3);
for _i in 0..range_size { for _i in 0..range_size {
row.push(' '); row.push(' ');
} }
@ -116,11 +126,12 @@ impl Display for Heatmap {
let commits = self.commits.len().to_string(); let commits = self.commits.len().to_string();
let authors = self.commits.iter().unique_by(|c| &c.author.name).count(); let authors = self.commits.iter().unique_by(|c| &c.author.name).count();
write!(f, "{} - {}\n", start_date, end_date).unwrap(); writeln!(f, "{} - {}", start_date, end_date).unwrap();
write!(f, "{} repo(s)\n", self.repos).unwrap(); writeln!(f, "{} repo(s)", self.repos).unwrap();
write!(f, "{} author(s)\n", authors).unwrap(); writeln!(f, "{} author(s)", authors).unwrap();
write!(f, "{} commit(s)\n\n", commits).unwrap(); writeln!(f, "{} commit(s)\n", commits).unwrap();
write!(f, "{}\n", self.months_row()).unwrap();
writeln!(f, "{}", self.months_row()).unwrap();
for (day, row) in DAYS.iter().zip(&self.data) { for (day, row) in DAYS.iter().zip(&self.data) {
write!(f, "{day} ").unwrap(); write!(f, "{day} ").unwrap();
@ -128,22 +139,29 @@ impl Display for Heatmap {
match val { match val {
x if *x >= 0 => { x if *x >= 0 => {
let color = &get_color_map()[get_color(*val, self.highest_count)]; let color = &get_color_map()[get_color(*val, self.highest_count)];
write!(f, "{color}{}{RESET} ", get_char()).unwrap(); match self.format {
} Format::Chars => write!(f, "{color}{}{RESET} ", get_char()).unwrap(),
x if *x < 0 => { Format::Numbers => {
write!(f, "{RESET} ").unwrap(); let val = val.min(&99);
write!(f, "{color}{:0>2}{RESET} ", val).unwrap();
}
}
} }
x if *x < 0 => match self.format {
Format::Chars => write!(f, "{RESET} ").unwrap(),
Format::Numbers => write!(f, "{RESET} ").unwrap(),
},
_ => {} _ => {}
} }
} }
write!(f, "\n").unwrap(); writeln!(f).unwrap();
} }
write!(f, "\nLess ").unwrap(); write!(f, "\nLess ").unwrap();
for color in get_color_map() { for color in get_color_map() {
write!(f, "{color}{}{RESET} ", get_char()).unwrap(); write!(f, "{color}{}{RESET} ", get_char()).unwrap();
} }
write!(f, " More\n").unwrap(); writeln!(f, " More").unwrap();
Ok(()) Ok(())
} }
@ -160,3 +178,9 @@ pub enum ColorLogic {
ByAmount, ByAmount,
ByWeight, ByWeight,
} }
#[derive(Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum Format {
Chars,
Numbers,
}

View File

@ -84,10 +84,11 @@ fn main() -> Result<()> {
let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap(); let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap();
let split_months = args.split_months; let split_months = args.split_months;
let format = args.format.clone();
let commits = get_commits(args, since, until).with_context(|| "Could not fetch commit list")?; let commits = get_commits(args, since, until).with_context(|| "Could not fetch commit list")?;
let heatmap = Heatmap::new(since, until, commits.0, commits.1, split_months); let heatmap = Heatmap::new(since, until, commits.0, commits.1, split_months, format);
println!("{heatmap}"); println!("{heatmap}");