Compare commits
No commits in common. "468f6a4eba022c9578aa63b0902bbaf9bb4918c9" and "90bd9ac376a5528b49ee287a331bd7b5041b4403" have entirely different histories.
468f6a4eba
...
90bd9ac376
|
@ -4,10 +4,6 @@ cargo-features = ["codegen-backend"]
|
|||
name = "git-heatmap"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Wynd <wyndftw@proton.me>"]
|
||||
description = "A simple and customizable heatmap for git repos"
|
||||
readme = "README.md"
|
||||
repository = "https://git.pixelatedw.xyz/wynd/git-heatmap"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
|
@ -42,17 +42,9 @@ $ git-heatmap -r "/path/to/repo" -b "main" -r "/other/repo" -b "test"
|
|||
# or to comply with the same number of branch lists per repo lists rule from above
|
||||
$ git-heatmap -r "/path/to/repo" -b "main" -r "other/repo" -b ""
|
||||
|
||||
# alternatively you can simply pass a root directory and let the program search for all git projects
|
||||
# do be warned that doing so means you're losing the customization aspect of choosing
|
||||
# which branches should be checked per repo, in this case all branches will be checked.
|
||||
$ git-heatmap --root-dir "/path"
|
||||
|
||||
# by default merges are counted so using --no-merges ensures they won't be counted
|
||||
$ git-heatmap --no-merges
|
||||
|
||||
# splits the heatmap per month instead of one big chunk
|
||||
$ git-heatmap --split-months
|
||||
|
||||
# by default it colors every day based on which one the maximum number of commits in a visible day
|
||||
# shading all the others accordingly, with by-amount it will instead color each day based on
|
||||
# the amount of commits in that day
|
||||
|
|
|
@ -6,11 +6,8 @@ use clap::{arg, Parser, ValueHint};
|
|||
use crate::heatmap::{ColorLogic, HeatmapColors};
|
||||
|
||||
#[derive(Clone, Debug, Parser, PartialEq, Eq)]
|
||||
#[command(version, about, author, long_about = None)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct CliArgs {
|
||||
#[arg(long("root-dir"), value_hint = ValueHint::DirPath)]
|
||||
pub root_dir: Option<PathBuf>,
|
||||
|
||||
#[arg(short, long, num_args(0..))]
|
||||
pub authors: Option<Vec<String>>,
|
||||
|
||||
|
@ -32,9 +29,6 @@ pub struct CliArgs {
|
|||
#[arg(long("until"))]
|
||||
pub until: Option<String>,
|
||||
|
||||
#[arg(long("split-months"), help("Split months"), default_value_t = false)]
|
||||
pub split_months: bool,
|
||||
|
||||
#[arg(long("no-merges"), default_value_t = false)]
|
||||
pub no_merges: bool,
|
||||
|
||||
|
|
|
@ -17,13 +17,7 @@ pub struct Heatmap {
|
|||
}
|
||||
|
||||
impl Heatmap {
|
||||
pub fn new(
|
||||
since: NaiveDate,
|
||||
until: NaiveDate,
|
||||
repos: usize,
|
||||
commits: Vec<Commit>,
|
||||
split_months: bool,
|
||||
) -> Self {
|
||||
pub fn new(since: NaiveDate, until: NaiveDate, repos: usize, commits: Vec<Commit>) -> Self {
|
||||
let mut heatmap = Self {
|
||||
data: [vec![], vec![], vec![], vec![], vec![], vec![], vec![]],
|
||||
since,
|
||||
|
@ -52,19 +46,6 @@ impl Heatmap {
|
|||
}
|
||||
|
||||
while current_day <= until {
|
||||
if split_months {
|
||||
let last_day_of_month =
|
||||
heatmap.last_day_of_month(current_day.year_ce().1 as i32, current_day.month());
|
||||
|
||||
// If current day is the last of the month we add 2 weeks worth of empty space so
|
||||
// months are more visible
|
||||
if last_day_of_month == current_day {
|
||||
for i in 0..14 {
|
||||
heatmap.data[(i as usize) % 7].push(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let month_name = current_day.format("%b").to_string();
|
||||
|
||||
if current_day == since {
|
||||
|
@ -94,13 +75,6 @@ impl Heatmap {
|
|||
heatmap
|
||||
}
|
||||
|
||||
fn last_day_of_month(&self, year: i32, month: u32) -> NaiveDate {
|
||||
NaiveDate::from_ymd_opt(year, month + 1, 1)
|
||||
.unwrap_or_else(|| NaiveDate::from_ymd(year + 1, 1, 1))
|
||||
.pred_opt()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn months_row(&self) -> String {
|
||||
let mut row = " ".to_string();
|
||||
|
||||
|
@ -170,3 +144,4 @@ pub enum ColorLogic {
|
|||
ByAmount,
|
||||
ByWeight,
|
||||
}
|
||||
|
||||
|
|
56
src/main.rs
56
src/main.rs
|
@ -2,12 +2,7 @@
|
|||
#![feature(let_chains)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::{
|
||||
cmp::Reverse,
|
||||
collections::HashSet,
|
||||
path::{self, PathBuf},
|
||||
sync::OnceLock,
|
||||
};
|
||||
use std::{cmp::Reverse, collections::HashSet, path::PathBuf, sync::OnceLock};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use chrono::{DateTime, Duration, Local, NaiveDate, TimeZone};
|
||||
|
@ -89,11 +84,9 @@ fn main() -> Result<()> {
|
|||
.unwrap_or_else(|| get_default_until(since));
|
||||
let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap();
|
||||
|
||||
let split_months = args.split_months;
|
||||
|
||||
let commits = get_commits(args, since).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);
|
||||
|
||||
println!("{heatmap}");
|
||||
|
||||
|
@ -154,45 +147,15 @@ fn get_color_map() -> Vec<String> {
|
|||
.to_vec()
|
||||
}
|
||||
|
||||
fn find_git_repos(scan_path: &path::Path, repos: &mut Vec<PathBuf>, _args: &CliArgs) {
|
||||
let Ok(dirs) = scan_path.read_dir()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
let dirs: Vec<_> = dirs
|
||||
.filter_map(|f| f.ok())
|
||||
.filter(|f| f.file_type().is_ok_and(|t| t.is_dir()))
|
||||
.collect_vec();
|
||||
|
||||
let dirs = dirs.iter().map(|f| f.path());
|
||||
|
||||
for dir in dirs {
|
||||
let filename = dir.file_name().unwrap_or_default().to_string_lossy();
|
||||
match filename.as_ref() {
|
||||
".git" => repos.push(dir),
|
||||
_ => find_git_repos(&dir, repos, _args),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commit>)> {
|
||||
let mut commits: HashSet<Commit> = HashSet::new();
|
||||
|
||||
let (repos, branches) = match &args.root_dir {
|
||||
Some(root) => {
|
||||
let mut repos: Vec<PathBuf> = vec![];
|
||||
find_git_repos(root, &mut repos, &args);
|
||||
let branches = vec!["".to_string(); repos.len()];
|
||||
(repos, branches)
|
||||
}
|
||||
None => {
|
||||
let repos = match args.repos {
|
||||
Some(r) => r,
|
||||
None => vec![PathBuf::from(".")],
|
||||
};
|
||||
|
||||
let branches = args.branches.unwrap_or_else(|| vec!["".to_string()]);
|
||||
let branches = args.branches.unwrap_or_else(|| vec!["@".to_string()]);
|
||||
|
||||
if repos.len() > 1 && repos.len() != branches.len() {
|
||||
return Err(anyhow!(
|
||||
|
@ -201,16 +164,12 @@ fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commi
|
|||
branches.len()
|
||||
));
|
||||
}
|
||||
(repos, branches)
|
||||
}
|
||||
};
|
||||
|
||||
let current_time = Local::now().time();
|
||||
let start_date = start_date.and_time(current_time);
|
||||
let start_date = Local.from_local_datetime(&start_date).unwrap();
|
||||
|
||||
let authors = args.authors.unwrap_or_default();
|
||||
let mut repos_count = 0;
|
||||
|
||||
for (i, repo_path) in repos.iter().enumerate() {
|
||||
let repo = gix::open(repo_path).unwrap();
|
||||
|
@ -226,7 +185,6 @@ fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commi
|
|||
}
|
||||
|
||||
let mailmap = Mailmap::new(repo_path);
|
||||
let mut has_commits = false;
|
||||
|
||||
for branch in branches {
|
||||
let branch_commits = repo
|
||||
|
@ -278,8 +236,6 @@ fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commi
|
|||
return None;
|
||||
}
|
||||
|
||||
has_commits = true;
|
||||
|
||||
Some(Commit {
|
||||
id: c.id,
|
||||
title,
|
||||
|
@ -291,10 +247,6 @@ fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commi
|
|||
commits.insert(c);
|
||||
});
|
||||
}
|
||||
|
||||
if has_commits {
|
||||
repos_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let commits = commits
|
||||
|
@ -302,5 +254,5 @@ fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commi
|
|||
.sorted_by_cached_key(|a| Reverse(a.time))
|
||||
.collect_vec();
|
||||
|
||||
Ok((repos_count, commits))
|
||||
Ok((repos.len(), commits))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue