Compare commits

..

No commits in common. "3bd86bac9844d468a96f8f368b5eee0fbf21ddcc" and "cb50649d855e9999391bf596d40c4a53974bc01a" have entirely different histories.

7 changed files with 741 additions and 141 deletions

811
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ cargo-features = ["codegen-backend"]
[package]
name = "git-heatmap"
version = "1.1.0"
version = "1.0.3"
edition = "2021"
authors = ["Wynd <wyndftw@proton.me>"]
description = "A simple and customizable heatmap for git repos"
@ -16,11 +16,11 @@ license = "MIT"
unsafe_code = { level = "forbid" }
[dependencies]
gix = { version = "0.66.0", default-features = false, features = ["mailmap"] }
clap = { version = "4.5.20", features = ["derive"] }
gix = { version = "0.64.0" }
clap = { version = "4.5.13", features = ["derive"] }
chrono = { version = "0.4.38" }
itertools = { version = "0.13.0" }
anyhow = { version = "1.0.89" }
anyhow = { version = "1.0.86" }
[profile.dev]
codegen-backend = "cranelift"

View File

@ -65,11 +65,6 @@ $ git-heatmap --split-months
# the amount of commits in that day
$ 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)
# without an -a flag all authors will be checked
$ git-heatmap -a "username" -a "other"

View File

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

View File

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

View File

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

View File

@ -84,11 +84,10 @@ fn main() -> Result<()> {
let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap();
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 heatmap = Heatmap::new(since, until, commits.0, commits.1, split_months, format);
let heatmap = Heatmap::new(since, until, commits.0, commits.1, split_months);
println!("{heatmap}");