From 4001dd9328a2f9e863cc25186902cbee2dc4fd00 Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 23 Jan 2023 13:48:57 +0100 Subject: [PATCH] Print commit time --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 5e703a8..793038e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -655,6 +655,7 @@ dependencies = [ "git-repository", "terminal_size", "textplots", + "time", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7bef042..402d395 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ clap = { version = "4.1.1", features = ["derive", "deprecated"] } git-repository = "0.33.0" terminal_size = "0.2.3" textplots = "0.8.0" +time = "0.3.17" diff --git a/src/main.rs b/src/main.rs index a04c247..c9bd809 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,10 @@ use git_repository::{ }; use terminal_size::{Height, Width}; use textplots::{Chart, Plot, Shape}; +use time::{format_description::FormatItem, macros::format_description}; + +const TIME_FORMAT: &[FormatItem<'_>] = + format_description!("[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour sign:mandatory]:[offset_minute]:[offset_second]"); #[derive(Debug, Parser)] struct Args { @@ -63,8 +67,9 @@ fn main() -> anyhow::Result<()> { let mut line_cache = HashMap::new(); for ancestor in commit.ancestors().all()? { let ancestor = repo.find_object(ancestor.unwrap())?.try_into_commit()?; + let time = ancestor.time()?.format(TIME_FORMAT); let line_count = count_lines(&repo, &ancestor, &mut line_cache)?; - println!("{} {line_count}", ancestor.id); + println!("{} {time} - {line_count}", ancestor.id); lines.push(line_count); }