Added option to use author time instead of commit time

master
Wynd 2025-09-06 01:00:44 +03:00
parent 38daf4ac4c
commit df4b44eba1
2 changed files with 33 additions and 10 deletions

View File

@ -52,6 +52,9 @@ pub struct CliArgs {
#[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,

View File

@ -180,6 +180,7 @@ pub fn get_commits(
});
let repo = repo.to_thread_local();
let mut cached_commits: Vec<Commit> = vec![];
let branch_commits = branch_commits
.into_iter()
@ -215,7 +216,18 @@ pub fn get_commits(
let email = author.email.to_string();
let name = author.name.to_string();
// let time = author.time().unwrap();
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);
@ -224,20 +236,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();