Removed git2 entirely, better label plurals and branches count label

master
Wynd 2024-12-03 22:04:07 +02:00
parent 6f30df1d6a
commit bcf4aad0d1
4 changed files with 40 additions and 107 deletions

61
Cargo.lock generated
View File

@ -137,8 +137,6 @@ version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fb8dd288a69fc53a1996d7ecfbf4a20d59065bff137ce7e56bbd620de191189" checksum = "5fb8dd288a69fc53a1996d7ecfbf4a20d59065bff137ce7e56bbd620de191189"
dependencies = [ dependencies = [
"jobserver",
"libc",
"shlex", "shlex",
] ]
@ -307,24 +305,10 @@ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
"clap", "clap",
"git2",
"gix", "gix",
"itertools", "itertools",
] ]
[[package]]
name = "git2"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724"
dependencies = [
"bitflags",
"libc",
"libgit2-sys",
"log",
"url",
]
[[package]] [[package]]
name = "gix" name = "gix"
version = "0.66.0" version = "0.66.0"
@ -932,15 +916,6 @@ dependencies = [
"jiff-tzdb", "jiff-tzdb",
] ]
[[package]]
name = "jobserver"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.70" version = "0.3.70"
@ -956,18 +931,6 @@ version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "libgit2-sys"
version = "0.17.0+1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224"
dependencies = [
"cc",
"libc",
"libz-sys",
"pkg-config",
]
[[package]] [[package]]
name = "libredox" name = "libredox"
version = "0.1.3" version = "0.1.3"
@ -979,18 +942,6 @@ dependencies = [
"redox_syscall", "redox_syscall",
] ]
[[package]]
name = "libz-sys"
version = "1.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.4.14" version = "0.4.14"
@ -1081,12 +1032,6 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pkg-config"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.86" version = "1.0.86"
@ -1301,12 +1246,6 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.5" version = "0.9.5"

View File

@ -17,7 +17,6 @@ unsafe_code = { level = "forbid" }
[dependencies] [dependencies]
gix = { version = "0.66.0", default-features = false, features = ["mailmap"] } gix = { version = "0.66.0", default-features = false, features = ["mailmap"] }
git2 = { version = "0.19.0", default-features = false }
clap = { version = "4.5.20", features = ["derive"] } clap = { version = "4.5.20", features = ["derive"] }
chrono = { version = "0.4.38" } chrono = { version = "0.4.38" }
itertools = { version = "0.13.0" } itertools = { version = "0.13.0" }

View File

@ -14,6 +14,7 @@ pub struct Heatmap {
until: NaiveDate, until: NaiveDate,
commits: Vec<Commit>, commits: Vec<Commit>,
highest_count: i32, highest_count: i32,
branches: usize,
repos: usize, repos: usize,
chunks: Vec<Chunk>, chunks: Vec<Chunk>,
@ -25,6 +26,7 @@ impl Heatmap {
since: NaiveDate, since: NaiveDate,
until: NaiveDate, until: NaiveDate,
repos: usize, repos: usize,
branches: usize,
commits: Vec<Commit>, commits: Vec<Commit>,
split_months: bool, split_months: bool,
months_per_row: u16, months_per_row: u16,
@ -35,6 +37,7 @@ impl Heatmap {
until, until,
commits, commits,
highest_count: 0, highest_count: 0,
branches,
repos, repos,
chunks: vec![], chunks: vec![],
format, format,
@ -118,13 +121,28 @@ impl Display for Heatmap {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let start_date = self.since.format("%Y-%b-%d").to_string(); let start_date = self.since.format("%Y-%b-%d").to_string();
let end_date = self.until.format("%Y-%b-%d").to_string(); let end_date = self.until.format("%Y-%b-%d").to_string();
let commits = self.commits.len().to_string(); let commits = self.commits.len();
let authors = self.commits.iter().unique_by(|c| &c.author.name).count(); let authors = self.commits.iter().unique_by(|c| &c.author.name).count();
let repos_label = if self.repos == 1 { "repo" } else { "repos" };
let branches_label = if self.branches == 1 {
"branch"
}
else {
"branches"
};
let authors_label = if authors == 1 { "author" } else { "authors" };
let commits_label = if commits == 1 { "commit" } else { "commits" };
writeln!(f, "{} - {}", start_date, end_date).unwrap(); writeln!(f, "{} - {}", start_date, end_date).unwrap();
writeln!(f, "{} repo(s)", self.repos).unwrap(); writeln!(
writeln!(f, "{} author(s)", authors).unwrap(); f,
writeln!(f, "{} commit(s)\n", commits).unwrap(); "{} {} | {} {}",
self.repos, repos_label, self.branches, branches_label
)
.unwrap();
writeln!(f, "{} {}", authors, authors_label).unwrap();
writeln!(f, "{} {}\n", commits, commits_label).unwrap();
for chunk in &self.chunks { for chunk in &self.chunks {
chunk.display(self, f); chunk.display(self, f);

View File

@ -10,7 +10,6 @@ use std::{
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use chrono::{DateTime, Duration, Local, NaiveDate, NaiveTime, TimeZone}; use chrono::{DateTime, Duration, Local, NaiveDate, NaiveTime, TimeZone};
use clap::Parser; use clap::Parser;
use git2::BranchType;
use gix::{bstr::ByteSlice, traverse::commit::simple::Sorting, ObjectId}; use gix::{bstr::ByteSlice, traverse::commit::simple::Sorting, ObjectId};
use heatmap::{ColorLogic, HeatmapColors}; use heatmap::{ColorLogic, HeatmapColors};
use itertools::Itertools; use itertools::Itertools;
@ -95,6 +94,7 @@ fn main() -> Result<()> {
until, until,
commits.0, commits.0,
commits.1, commits.1,
commits.2,
split_months, split_months,
months_per_row, months_per_row,
format, format,
@ -190,7 +190,7 @@ fn get_commits(
args: CliArgs, args: CliArgs,
start_date: NaiveDate, start_date: NaiveDate,
end_date: NaiveDate, end_date: NaiveDate,
) -> Result<(usize, Vec<Commit>)> { ) -> Result<(usize, usize, Vec<Commit>)> {
let mut commits: HashSet<Commit> = HashSet::new(); let mut commits: HashSet<Commit> = HashSet::new();
let ignored_repos = args.ignored_repos.as_ref().unwrap_or(&vec![]).to_owned(); let ignored_repos = args.ignored_repos.as_ref().unwrap_or(&vec![]).to_owned();
@ -231,56 +231,33 @@ fn get_commits(
let authors = args.authors.unwrap_or_default(); let authors = args.authors.unwrap_or_default();
let mut repos_count = 0; let mut repos_count = 0;
let mut branches_count = 0;
for (i, repo_path) in repos.iter().enumerate() { for (i, repo_path) in repos.iter().enumerate() {
let gix_repo = gix::open(repo_path).unwrap(); let repo = gix::open(repo_path).unwrap();
let git2_repo = git2::Repository::open(repo_path).unwrap();
let branch_names = &*branches[i]; let branch_names = &*branches[i];
let mut branches = vec![]; let mut branches = vec![];
if branch_names.is_empty() { if branch_names.is_empty() {
// NOTE: Gix's branch_names doesn't seem return ALL local branches but only the master branches = repo
// branch and remote ones. The documentation doesn't help at all either so...for now .references()?
// git2 will do. .prefixed("refs/heads")?
// .filter_map(Result::ok)
// dbg!(&repo.branch_names());
//
// if repo.branch_names().is_empty() {
// branches.extend(["@"]);
// }
// else {
// branches.extend(repo.branch_names().iter());
// }
branches = git2_repo
.branches(Some(BranchType::Local))
.unwrap()
.map_ok(|(b, _)| b)
.filter_map(|b| { .filter_map(|b| {
if let Ok(branch) = b { b.inner
Some(branch) .name
} .to_string()
else { .strip_prefix("refs/heads/")
None .map(|s| s.to_string())
}
})
.filter_map(|b| {
if let Ok(result) = b.name()
&& let Some(name) = result
{
return Some(name.to_string());
}
None
}) })
.collect_vec(); .collect_vec();
} }
else { else {
let branch_names = branch_names.split(' ').map(|b| b.to_string()); let branch_names = branch_names.split(' ').map(|s| s.to_string());
branches.extend(branch_names); branches.extend(branch_names);
} }
// dbg!(&branches); branches_count += branches.len();
let mailmap = Mailmap::new(repo_path); let mailmap = Mailmap::new(repo_path);
let mut has_commits = false; let mut has_commits = false;
@ -288,7 +265,7 @@ fn get_commits(
for branch in branches { for branch in branches {
// When passing the default @ (HEAD) branch this might actually not exist at all // When passing the default @ (HEAD) branch this might actually not exist at all
// locally so we're skipping it // locally so we're skipping it
let Ok(rev) = gix_repo.rev_parse(&*branch) let Ok(rev) = repo.rev_parse(&*branch)
else { else {
continue; continue;
}; };
@ -365,5 +342,5 @@ fn get_commits(
.sorted_by_cached_key(|a| Reverse(a.time)) .sorted_by_cached_key(|a| Reverse(a.time))
.collect_vec(); .collect_vec();
Ok((repos_count, commits)) Ok((repos_count, branches_count, commits))
} }