CLI option to list commits + made the caching commits vec global
parent
f04b6b2b2e
commit
66e7a76956
|
|
@ -66,9 +66,12 @@ pub struct CliArgs {
|
||||||
|
|
||||||
#[arg(long("list-days"), default_value_t = false)]
|
#[arg(long("list-days"), default_value_t = false)]
|
||||||
pub list_days: bool,
|
pub list_days: bool,
|
||||||
|
|
||||||
|
#[arg(long("list-commits"), default_value_t = false)]
|
||||||
|
pub list_commits: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_since_date() -> String {
|
fn get_since_date() -> String {
|
||||||
let date = Local::now() - Duration::days(364);
|
let date = Local::now() - Duration::days(364);
|
||||||
date.format("%Y-%m-%d").to_string()
|
date.format("%Y-%m-%d").to_string()
|
||||||
}
|
}
|
||||||
18
src/lib.rs
18
src/lib.rs
|
|
@ -50,11 +50,11 @@ pub const RED_COLOR_MAP: [Rgb; 5] = [
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Commit {
|
pub struct Commit {
|
||||||
id: ObjectId,
|
pub id: ObjectId,
|
||||||
title: String,
|
pub title: String,
|
||||||
author: Author,
|
pub author: Author,
|
||||||
repo: String,
|
pub repo: String,
|
||||||
time: DateTime<Local>,
|
pub time: DateTime<Local>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Commit {
|
impl Commit {
|
||||||
|
|
@ -81,8 +81,8 @@ impl Commit {
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||||
pub struct Author {
|
pub struct Author {
|
||||||
name: String,
|
pub name: String,
|
||||||
email: String,
|
pub email: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn args() -> CliArgs {
|
pub fn args() -> CliArgs {
|
||||||
|
|
@ -122,7 +122,7 @@ pub fn get_commits(
|
||||||
(repos, branches)
|
(repos, branches)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let mut repos = match args.repos {
|
let repos = match args.repos {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => vec![PathBuf::from(".")],
|
None => vec![PathBuf::from(".")],
|
||||||
};
|
};
|
||||||
|
|
@ -152,6 +152,7 @@ pub fn get_commits(
|
||||||
|
|
||||||
let mut repos_count: usize = 0;
|
let mut repos_count: usize = 0;
|
||||||
let mut branches_count: usize = 0;
|
let mut branches_count: usize = 0;
|
||||||
|
let mut cached_commits: Vec<Commit> = vec![];
|
||||||
|
|
||||||
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();
|
||||||
|
|
@ -183,7 +184,6 @@ pub fn get_commits(
|
||||||
});
|
});
|
||||||
|
|
||||||
let repo = repo.to_thread_local();
|
let repo = repo.to_thread_local();
|
||||||
let mut cached_commits: Vec<Commit> = vec![];
|
|
||||||
|
|
||||||
let branch_commits = branch_commits
|
let branch_commits = branch_commits
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
||||||
49
src/main.rs
49
src/main.rs
|
|
@ -1,6 +1,10 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use chrono::NaiveDate;
|
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<()> {
|
fn main() -> Result<()> {
|
||||||
let args = libgitheatmap::args();
|
let args = libgitheatmap::args();
|
||||||
|
|
@ -18,24 +22,39 @@ fn main() -> Result<()> {
|
||||||
let format = args.format;
|
let format = args.format;
|
||||||
let list_repos = args.list_repos;
|
let list_repos = args.list_repos;
|
||||||
let list_days = args.list_days;
|
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")?;
|
.with_context(|| "Could not fetch commit list")?;
|
||||||
|
|
||||||
let heatmap = Heatmap::new(
|
if list_commits {
|
||||||
since,
|
// Newer entries at the bottom, older entries at top
|
||||||
until,
|
commits.2.reverse();
|
||||||
commits.0,
|
for commit in commits.2 {
|
||||||
commits.1,
|
let repo = format!("{}{}", REPO_COLOR.to_ansi(), commit.repo);
|
||||||
commits.2,
|
let author = format!("{}{}", AUTHOR_COLOR.to_ansi(), commit.author.name);
|
||||||
split_months,
|
let time = format!("{}{}", TIME_COLOR.to_ansi(), commit.time);
|
||||||
months_per_row,
|
let message = commit.title;
|
||||||
format,
|
|
||||||
list_repos,
|
|
||||||
list_days,
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("{heatmap}");
|
println!("{repo} {author} {time}\n{RESET}{message}\n",);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let heatmap = Heatmap::new(
|
||||||
|
since,
|
||||||
|
until,
|
||||||
|
commits.0,
|
||||||
|
commits.1,
|
||||||
|
commits.2,
|
||||||
|
split_months,
|
||||||
|
months_per_row,
|
||||||
|
format,
|
||||||
|
list_repos,
|
||||||
|
list_days,
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("{heatmap}");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue