diff --git a/gitoxide-core/src/hours.rs b/gitoxide-core/src/hours.rs index 5ec57db8eb2..7e30b3caae2 100644 --- a/gitoxide-core/src/hours.rs +++ b/gitoxide-core/src/hours.rs @@ -1,6 +1,5 @@ use std::{ collections::{hash_map::Entry, HashMap}, - ffi::OsStr, io, path::Path, time::Instant, @@ -8,14 +7,13 @@ use std::{ use anyhow::{anyhow, bail}; use git_repository as git; +use git_repository::bstr::BStr; use git_repository::{ actor, bstr::{BString, ByteSlice}, interrupt, objs, prelude::*, - progress, - refs::file::ReferenceExt, - Progress, + progress, Progress, }; use itertools::Itertools; use rayon::prelude::*; @@ -41,7 +39,7 @@ pub struct Context { /// * _progress_ - A way to provide progress and performance information pub fn estimate( working_dir: &Path, - refname: &OsStr, + rev_spec: &BStr, mut progress: P, Context { show_pii, @@ -55,15 +53,7 @@ where P: Progress, { let repo = git::discover(working_dir)?.apply_environment(); - let commit_id = repo - .refs - .find(refname.to_string_lossy().as_ref())? - .peel_to_id_in_place(&repo.refs, |oid, buf| { - repo.objects - .try_find(oid, buf) - .map(|obj| obj.map(|obj| (obj.kind, obj.data))) - })? - .to_owned(); + let commit_id = repo.rev_parse_single(rev_spec)?; let (all_commits, is_shallow) = { let start = Instant::now(); @@ -71,7 +61,7 @@ where progress.init(None, progress::count("commits")); let mut commits: Vec> = Vec::new(); let commit_iter = interrupt::Iter::new( - commit_id.ancestors(|oid, buf| { + commit_id.detach().ancestors(|oid, buf| { progress.inc(); repo.objects.find(oid, buf).map(|o| { commits.push(o.data.to_owned()); diff --git a/src/porcelain/main.rs b/src/porcelain/main.rs index 6de13d10f7c..e0656617e30 100644 --- a/src/porcelain/main.rs +++ b/src/porcelain/main.rs @@ -38,7 +38,7 @@ pub fn main() -> Result<()> { Subcommands::Tool(tool) => match tool { crate::porcelain::options::ToolCommands::EstimateHours(crate::porcelain::options::EstimateHours { working_dir, - refname, + rev_spec, no_bots, show_pii, omit_unify_identities, @@ -53,7 +53,7 @@ pub fn main() -> Result<()> { move |progress, out, _err| { hours::estimate( &working_dir, - &refname, + rev_spec.as_ref(), progress, hours::Context { show_pii, diff --git a/src/porcelain/options.rs b/src/porcelain/options.rs index e949fed06c2..5ee5774321f 100644 --- a/src/porcelain/options.rs +++ b/src/porcelain/options.rs @@ -1,4 +1,6 @@ -use std::{ffi::OsString, path::PathBuf}; +use git::bstr::BString; +use git_repository as git; +use std::path::PathBuf; #[derive(Debug, clap::Parser)] #[clap(about = "The rusty git", version = clap::crate_version!())] @@ -93,9 +95,9 @@ pub struct EstimateHours { #[clap(validator_os = validator::is_repo)] #[clap(default_value = ".")] pub working_dir: PathBuf, - /// The name of the ref like 'HEAD' or 'main' at which to start iterating the commit graph. - #[clap(default_value("HEAD"))] - pub refname: OsString, + /// The name of the revision as spec, like 'HEAD' or 'main' at which to start iterating the commit graph. + #[clap(default_value("HEAD"), parse(try_from_os_str = git::env::os_str_to_bstring))] + pub rev_spec: BString, /// Ignore github bots which match the `[bot]` search string. #[clap(short = 'b', long)] pub no_bots: bool,