diff --git a/Cargo.lock b/Cargo.lock index 8e4a980..4eb3bf0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,8 +137,6 @@ version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fb8dd288a69fc53a1996d7ecfbf4a20d59065bff137ce7e56bbd620de191189" dependencies = [ - "jobserver", - "libc", "shlex", ] @@ -307,24 +305,10 @@ dependencies = [ "anyhow", "chrono", "clap", - "git2", "gix", "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]] name = "gix" version = "0.66.0" @@ -932,15 +916,6 @@ dependencies = [ "jiff-tzdb", ] -[[package]] -name = "jobserver" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.70" @@ -956,18 +931,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "libredox" version = "0.1.3" @@ -979,18 +942,6 @@ dependencies = [ "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]] name = "linux-raw-sys" version = "0.4.14" @@ -1081,12 +1032,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "proc-macro2" version = "1.0.86" @@ -1301,12 +1246,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" diff --git a/Cargo.toml b/Cargo.toml index f23dcd0..5ca2cf2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ unsafe_code = { level = "forbid" } [dependencies] 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"] } chrono = { version = "0.4.38" } itertools = { version = "0.13.0" } @@ -32,4 +31,4 @@ incremental = true opt-level = 3 strip = true lto = true -codegen-units = 1 \ No newline at end of file +codegen-units = 1 diff --git a/src/heatmap.rs b/src/heatmap.rs index ecbd5e8..46c0e14 100644 --- a/src/heatmap.rs +++ b/src/heatmap.rs @@ -14,6 +14,7 @@ pub struct Heatmap { until: NaiveDate, commits: Vec, highest_count: i32, + branches: usize, repos: usize, chunks: Vec, @@ -25,6 +26,7 @@ impl Heatmap { since: NaiveDate, until: NaiveDate, repos: usize, + branches: usize, commits: Vec, split_months: bool, months_per_row: u16, @@ -35,6 +37,7 @@ impl Heatmap { until, commits, highest_count: 0, + branches, repos, chunks: vec![], format, @@ -118,13 +121,28 @@ impl Display for Heatmap { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let start_date = self.since.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 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, "{} repo(s)", self.repos).unwrap(); - writeln!(f, "{} author(s)", authors).unwrap(); - writeln!(f, "{} commit(s)\n", commits).unwrap(); + writeln!( + f, + "{} {} | {} {}", + 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 { chunk.display(self, f); diff --git a/src/main.rs b/src/main.rs index 9963fa1..1c43943 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ use std::{ use anyhow::{anyhow, Context, Result}; use chrono::{DateTime, Duration, Local, NaiveDate, NaiveTime, TimeZone}; use clap::Parser; -use git2::BranchType; use gix::{bstr::ByteSlice, traverse::commit::simple::Sorting, ObjectId}; use heatmap::{ColorLogic, HeatmapColors}; use itertools::Itertools; @@ -95,6 +94,7 @@ fn main() -> Result<()> { until, commits.0, commits.1, + commits.2, split_months, months_per_row, format, @@ -190,7 +190,7 @@ fn get_commits( args: CliArgs, start_date: NaiveDate, end_date: NaiveDate, -) -> Result<(usize, Vec)> { +) -> Result<(usize, usize, Vec)> { let mut commits: HashSet = HashSet::new(); 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 mut repos_count = 0; + let mut branches_count = 0; for (i, repo_path) in repos.iter().enumerate() { - let gix_repo = gix::open(repo_path).unwrap(); - let git2_repo = git2::Repository::open(repo_path).unwrap(); + let repo = gix::open(repo_path).unwrap(); let branch_names = &*branches[i]; let mut branches = vec![]; if branch_names.is_empty() { - // NOTE: Gix's branch_names doesn't seem return ALL local branches but only the master - // branch and remote ones. The documentation doesn't help at all either so...for now - // git2 will do. - // - // 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) + branches = repo + .references()? + .prefixed("refs/heads")? + .filter_map(Result::ok) .filter_map(|b| { - if let Ok(branch) = b { - Some(branch) - } - else { - None - } - }) - .filter_map(|b| { - if let Ok(result) = b.name() - && let Some(name) = result - { - return Some(name.to_string()); - } - - None + b.inner + .name + .to_string() + .strip_prefix("refs/heads/") + .map(|s| s.to_string()) }) .collect_vec(); } 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); } - // dbg!(&branches); + branches_count += branches.len(); let mailmap = Mailmap::new(repo_path); let mut has_commits = false; @@ -288,7 +265,7 @@ fn get_commits( for branch in branches { // When passing the default @ (HEAD) branch this might actually not exist at all // locally so we're skipping it - let Ok(rev) = gix_repo.rev_parse(&*branch) + let Ok(rev) = repo.rev_parse(&*branch) else { continue; }; @@ -365,5 +342,5 @@ fn get_commits( .sorted_by_cached_key(|a| Reverse(a.time)) .collect_vec(); - Ok((repos_count, commits)) + Ok((repos_count, branches_count, commits)) }