Small optimization so it stops fetching and converting all commits

master
Wynd 2024-08-17 02:40:20 +03:00
parent cbbe8c44b0
commit 797ab6a9ac
2 changed files with 10 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target /target
profile.json

View File

@ -7,9 +7,9 @@ use std::{cmp::Reverse, collections::HashSet, path::PathBuf, sync::OnceLock};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use chrono::{DateTime, Duration, Local, NaiveDate, TimeZone}; use chrono::{DateTime, Duration, Local, NaiveDate, TimeZone};
use clap::Parser; use clap::Parser;
use gix::{bstr::ByteSlice, ObjectId, Repository}; use gix::{bstr::ByteSlice, traverse::commit::simple::Sorting, ObjectId};
use heatmap::HeatmapColors; use heatmap::HeatmapColors;
use itertools::{enumerate, Itertools}; use itertools::Itertools;
use rgb::Rgb; use rgb::Rgb;
use crate::{cli::CliArgs, heatmap::Heatmap}; use crate::{cli::CliArgs, heatmap::Heatmap};
@ -153,12 +153,19 @@ fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commi
branches.extend(branch_names); branches.extend(branch_names);
} }
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();
for branch in branches { for branch in branches {
let branch_commits = repo let branch_commits = repo
.rev_parse(branch)? .rev_parse(branch)?
.single() .single()
.unwrap() .unwrap()
.ancestors() .ancestors()
.sorting(Sorting::ByCommitTimeNewestFirstCutoffOlderThan {
seconds: start_date.timestamp(),
})
.all()?; .all()?;
branch_commits branch_commits
@ -179,10 +186,6 @@ fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commi
return None; return None;
} }
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 time = c.time().ok()?; let time = c.time().ok()?;
let time = let time =
DateTime::from_timestamp_millis(time.seconds * 1000)?.with_timezone(&Local); DateTime::from_timestamp_millis(time.seconds * 1000)?.with_timezone(&Local);