Added git2 dep to actually get all the local branches

master
Wynd 2024-10-21 23:45:34 +03:00
parent 3bd86bac98
commit 267e361849
3 changed files with 105 additions and 10 deletions

61
Cargo.lock generated
View File

@ -137,6 +137,8 @@ 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",
] ]
@ -305,10 +307,24 @@ 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"
@ -916,6 +932,15 @@ 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"
@ -931,6 +956,18 @@ 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"
@ -942,6 +979,18 @@ 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"
@ -1032,6 +1081,12 @@ 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"
@ -1246,6 +1301,12 @@ 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,6 +17,7 @@ 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

@ -10,6 +10,7 @@ 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;
@ -223,30 +224,62 @@ fn get_commits(
let mut repos_count = 0; let mut repos_count = 0;
for (i, repo_path) in repos.iter().enumerate() { for (i, repo_path) in repos.iter().enumerate() {
let repo = gix::open(repo_path).unwrap(); let gix_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() {
if repo.branch_names().is_empty() { // NOTE: Gix's branch_names doesn't seem return ALL local branches but only the master
branches.extend(["@"]); // 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)
.filter_map(|b| {
if let Ok(branch) = b {
Some(branch)
} }
else { else {
branches.extend(repo.branch_names().iter()); None
} }
})
.filter_map(|b| {
if let Ok(result) = b.name()
&& let Some(name) = result
{
return Some(name.to_string());
}
None
})
.collect_vec();
} }
else { else {
let branch_names = branch_names.split(' '); let branch_names = branch_names.split(' ').map(|b| b.to_string());
branches.extend(branch_names); branches.extend(branch_names);
} }
// dbg!(&branches);
let mailmap = Mailmap::new(repo_path); let mailmap = Mailmap::new(repo_path);
let mut has_commits = false; let mut has_commits = false;
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) = repo.rev_parse(branch) let Ok(rev) = gix_repo.rev_parse(&*branch)
else { else {
continue; continue;
}; };