Compare commits
7 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
1d97cbfa45 | |
|
|
8f4a8c18f9 | |
|
|
66e7a76956 | |
|
|
f04b6b2b2e | |
|
|
df4b44eba1 | |
|
|
38daf4ac4c | |
|
|
5f830049dd |
|
|
@ -449,7 +449,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "git-heatmap"
|
||||
version = "1.4.0"
|
||||
version = "1.4.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ cargo-features = ["codegen-backend"]
|
|||
|
||||
[package]
|
||||
name = "git-heatmap"
|
||||
version = "1.4.0"
|
||||
version = "1.4.1"
|
||||
edition = "2024"
|
||||
authors = ["Wynd <wyndftw@proton.me>"]
|
||||
description = "A simple and customizable heatmap for git repos"
|
||||
|
|
|
|||
|
|
@ -84,5 +84,6 @@ $ git-heatmap -a "username" -a "other"
|
|||
$ git-heatmap --since "2013-08-23"
|
||||
|
||||
# or choose a time span, both --since and --until must use a YYYY-MM-DD format
|
||||
# --until can optionally use `today` as a keyword for the current date
|
||||
$ git-heatmap --since "2013-08-23" --until "2024-08-23"
|
||||
```
|
||||
|
|
|
|||
19
src/cli.rs
19
src/cli.rs
|
|
@ -32,7 +32,12 @@ pub struct CliArgs {
|
|||
#[arg(long("since"), default_value_t = get_since_date())]
|
||||
pub since: String,
|
||||
|
||||
#[arg(long("until"))]
|
||||
#[arg(
|
||||
long("until"),
|
||||
help(
|
||||
"Optional upper limit for the time slice being checked, defaults to 365 days after the `since` date.\n`today` can be used for current date."
|
||||
)
|
||||
)]
|
||||
pub until: Option<String>,
|
||||
|
||||
#[arg(long("split-months"), help("Split months"), default_value_t = false)]
|
||||
|
|
@ -48,6 +53,13 @@ pub struct CliArgs {
|
|||
#[arg(long("no-merges"), default_value_t = false)]
|
||||
pub no_merges: bool,
|
||||
|
||||
// Experimental
|
||||
#[arg(long("no-diff"), default_value_t = false)]
|
||||
pub no_diff: bool,
|
||||
|
||||
#[arg(long("use-author-time"), default_value_t = false)]
|
||||
pub use_author_time: bool,
|
||||
|
||||
#[arg(long("counting"), value_enum, default_value_t = ColorLogic::ByWeight)]
|
||||
pub counting: ColorLogic,
|
||||
|
||||
|
|
@ -59,9 +71,12 @@ pub struct CliArgs {
|
|||
|
||||
#[arg(long("list-days"), default_value_t = false)]
|
||||
pub list_days: bool,
|
||||
|
||||
#[arg(long("list-commits"), default_value_t = false)]
|
||||
pub list_commits: bool,
|
||||
}
|
||||
|
||||
fn get_since_date() -> String {
|
||||
let date = Local::now() - Duration::days(365);
|
||||
let date = Local::now() - Duration::days(364);
|
||||
date.format("%Y-%m-%d").to_string()
|
||||
}
|
||||
|
|
|
|||
86
src/lib.rs
86
src/lib.rs
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use std::{
|
||||
cmp::Reverse,
|
||||
fmt::Display,
|
||||
path::{self, PathBuf},
|
||||
sync::OnceLock,
|
||||
};
|
||||
|
|
@ -50,11 +51,11 @@ pub const RED_COLOR_MAP: [Rgb; 5] = [
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Commit {
|
||||
id: ObjectId,
|
||||
title: String,
|
||||
author: Author,
|
||||
repo: String,
|
||||
time: DateTime<Local>,
|
||||
pub id: ObjectId,
|
||||
pub title: String,
|
||||
pub author: Author,
|
||||
pub repo: String,
|
||||
pub time: DateTime<Local>,
|
||||
}
|
||||
|
||||
impl Commit {
|
||||
|
|
@ -81,8 +82,14 @@ impl Commit {
|
|||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
pub struct Author {
|
||||
name: String,
|
||||
email: String,
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
impl Display for Author {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!("{} <{}>", self.name, self.email))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn args() -> CliArgs {
|
||||
|
|
@ -122,11 +129,17 @@ pub fn get_commits(
|
|||
(repos, branches)
|
||||
}
|
||||
None => {
|
||||
let repos = match args.repos {
|
||||
let mut repos = match args.repos {
|
||||
Some(r) => r,
|
||||
None => vec![PathBuf::from(".")],
|
||||
};
|
||||
|
||||
// Turn any potential relative paths (such as `.`) into an absolute path
|
||||
repos = repos
|
||||
.iter_mut()
|
||||
.filter_map(|p| std::fs::canonicalize(p).ok())
|
||||
.collect_vec();
|
||||
|
||||
let branches = args.branches.unwrap_or_else(|| vec!["".to_string()]);
|
||||
|
||||
if repos.len() > 1 && repos.len() != branches.len() {
|
||||
|
|
@ -152,14 +165,18 @@ pub fn get_commits(
|
|||
|
||||
let mut repos_count: usize = 0;
|
||||
let mut branches_count: usize = 0;
|
||||
let mut cached_commits: Vec<Commit> = vec![];
|
||||
|
||||
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 mut repo_name = repo_path.file_name();
|
||||
if repo_path.ends_with(gix::discover::DOT_GIT_DIR) {
|
||||
if let Some(parent) = repo_path.parent() {
|
||||
repo_name = parent.file_name();
|
||||
};
|
||||
}
|
||||
|
||||
let repo_name = repo_name
|
||||
.iter()
|
||||
.filter_map(|r| r.to_str())
|
||||
|
|
@ -204,9 +221,30 @@ pub fn get_commits(
|
|||
|
||||
let author = c.author().ok()?;
|
||||
|
||||
// Ignores commits with different commit / author times
|
||||
// Usually due to rebases or cherry picking, however other edge cases may apply too
|
||||
if args.no_diff {
|
||||
let commit_info = c.committer().unwrap();
|
||||
if commit_info.time != author.time {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
let email = author.email.to_string();
|
||||
let name = author.name.to_string();
|
||||
|
||||
let time = if args.use_author_time {
|
||||
author.time().ok()?
|
||||
}
|
||||
else {
|
||||
c.time().ok()?
|
||||
};
|
||||
let time =
|
||||
DateTime::from_timestamp_millis(time.seconds * 1000)?.with_timezone(&Local);
|
||||
if time < start_date || time > end_date {
|
||||
return None;
|
||||
}
|
||||
|
||||
let author = Author { name, email };
|
||||
let author = mailmap.resolve(author);
|
||||
|
||||
|
|
@ -214,20 +252,28 @@ pub fn get_commits(
|
|||
return None;
|
||||
}
|
||||
|
||||
let time = c.time().ok()?;
|
||||
let time =
|
||||
DateTime::from_timestamp_millis(time.seconds * 1000)?.with_timezone(&Local);
|
||||
if time < start_date || time > end_date {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(Commit {
|
||||
let commit = Commit {
|
||||
id: c.id,
|
||||
title,
|
||||
author,
|
||||
repo: repo_name.to_string(),
|
||||
time,
|
||||
})
|
||||
};
|
||||
|
||||
if args.use_author_time {
|
||||
for other in &cached_commits {
|
||||
if other.author == commit.author
|
||||
&& other.title == commit.title
|
||||
&& other.time == commit.time
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
cached_commits.push(commit.clone());
|
||||
}
|
||||
|
||||
Some(commit)
|
||||
})
|
||||
.collect_vec();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ pub struct Mailmap {
|
|||
entries: Vec<MapEntry>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
struct MapEntry {
|
||||
new_name: Option<String>,
|
||||
|
|
|
|||
28
src/main.rs
28
src/main.rs
|
|
@ -1,6 +1,10 @@
|
|||
use anyhow::{Context, Result};
|
||||
use chrono::NaiveDate;
|
||||
use libgitheatmap::heatmap::Heatmap;
|
||||
use libgitheatmap::{RESET, heatmap::Heatmap, rgb::Rgb};
|
||||
|
||||
const REPO_COLOR: Rgb = Rgb(0, 255, 0);
|
||||
const AUTHOR_COLOR: Rgb = Rgb(200, 200, 0);
|
||||
const TIME_COLOR: Rgb = Rgb(0, 200, 200);
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = libgitheatmap::args();
|
||||
|
|
@ -11,17 +15,34 @@ fn main() -> Result<()> {
|
|||
.until
|
||||
.clone()
|
||||
.unwrap_or_else(|| libgitheatmap::get_default_until(since));
|
||||
let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap();
|
||||
let until = match until.to_lowercase().as_str() {
|
||||
"today" => chrono::Local::now().date_naive(),
|
||||
_ => NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap(),
|
||||
};
|
||||
|
||||
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 list_commits = args.list_commits;
|
||||
|
||||
let commits = libgitheatmap::get_commits(args, since, until)
|
||||
let mut commits = libgitheatmap::get_commits(args, since, until)
|
||||
.with_context(|| "Could not fetch commit list")?;
|
||||
|
||||
if list_commits {
|
||||
// Newer entries at the bottom, older entries at top
|
||||
commits.2.reverse();
|
||||
for commit in commits.2 {
|
||||
let repo = format!("{}{}", REPO_COLOR.to_ansi(), commit.repo);
|
||||
let author = format!("{}{}", AUTHOR_COLOR.to_ansi(), commit.author);
|
||||
let time = format!("{}{}", TIME_COLOR.to_ansi(), commit.time);
|
||||
let message = commit.title;
|
||||
|
||||
println!("{repo} {author} {time}\n{RESET}{message}\n",);
|
||||
}
|
||||
}
|
||||
else {
|
||||
let heatmap = Heatmap::new(
|
||||
since,
|
||||
until,
|
||||
|
|
@ -36,6 +57,7 @@ fn main() -> Result<()> {
|
|||
);
|
||||
|
||||
println!("{heatmap}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue