Skip to content

Commit cf7182e

Browse files
committed
use rev-specs instead of ref-names
1 parent 429cccc commit cf7182e

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

Diff for: gitoxide-core/src/hours.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
use std::{
22
collections::{hash_map::Entry, HashMap},
3-
ffi::OsStr,
43
io,
54
path::Path,
65
time::Instant,
76
};
87

98
use anyhow::{anyhow, bail};
109
use git_repository as git;
10+
use git_repository::bstr::BStr;
1111
use git_repository::{
1212
actor,
1313
bstr::{BString, ByteSlice},
1414
interrupt, objs,
1515
prelude::*,
16-
progress,
17-
refs::file::ReferenceExt,
18-
Progress,
16+
progress, Progress,
1917
};
2018
use itertools::Itertools;
2119
use rayon::prelude::*;
@@ -41,7 +39,7 @@ pub struct Context<W> {
4139
/// * _progress_ - A way to provide progress and performance information
4240
pub fn estimate<W, P>(
4341
working_dir: &Path,
44-
refname: &OsStr,
42+
rev_spec: &BStr,
4543
mut progress: P,
4644
Context {
4745
show_pii,
@@ -55,23 +53,15 @@ where
5553
P: Progress,
5654
{
5755
let repo = git::discover(working_dir)?.apply_environment();
58-
let commit_id = repo
59-
.refs
60-
.find(refname.to_string_lossy().as_ref())?
61-
.peel_to_id_in_place(&repo.refs, |oid, buf| {
62-
repo.objects
63-
.try_find(oid, buf)
64-
.map(|obj| obj.map(|obj| (obj.kind, obj.data)))
65-
})?
66-
.to_owned();
56+
let commit_id = repo.rev_parse_single(rev_spec)?;
6757

6858
let (all_commits, is_shallow) = {
6959
let start = Instant::now();
7060
let mut progress = progress.add_child("Traverse commit graph");
7161
progress.init(None, progress::count("commits"));
7262
let mut commits: Vec<Vec<u8>> = Vec::new();
7363
let commit_iter = interrupt::Iter::new(
74-
commit_id.ancestors(|oid, buf| {
64+
commit_id.detach().ancestors(|oid, buf| {
7565
progress.inc();
7666
repo.objects.find(oid, buf).map(|o| {
7767
commits.push(o.data.to_owned());

Diff for: src/porcelain/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn main() -> Result<()> {
3838
Subcommands::Tool(tool) => match tool {
3939
crate::porcelain::options::ToolCommands::EstimateHours(crate::porcelain::options::EstimateHours {
4040
working_dir,
41-
refname,
41+
rev_spec,
4242
no_bots,
4343
show_pii,
4444
omit_unify_identities,
@@ -53,7 +53,7 @@ pub fn main() -> Result<()> {
5353
move |progress, out, _err| {
5454
hours::estimate(
5555
&working_dir,
56-
&refname,
56+
rev_spec.as_ref(),
5757
progress,
5858
hours::Context {
5959
show_pii,

Diff for: src/porcelain/options.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::{ffi::OsString, path::PathBuf};
1+
use git::bstr::BString;
2+
use git_repository as git;
3+
use std::path::PathBuf;
24

35
#[derive(Debug, clap::Parser)]
46
#[clap(about = "The rusty git", version = clap::crate_version!())]
@@ -93,9 +95,9 @@ pub struct EstimateHours {
9395
#[clap(validator_os = validator::is_repo)]
9496
#[clap(default_value = ".")]
9597
pub working_dir: PathBuf,
96-
/// The name of the ref like 'HEAD' or 'main' at which to start iterating the commit graph.
97-
#[clap(default_value("HEAD"))]
98-
pub refname: OsString,
98+
/// The name of the revision as spec, like 'HEAD' or 'main' at which to start iterating the commit graph.
99+
#[clap(default_value("HEAD"), parse(try_from_os_str = git::env::os_str_to_bstring))]
100+
pub rev_spec: BString,
99101
/// Ignore github bots which match the `[bot]` search string.
100102
#[clap(short = 'b', long)]
101103
pub no_bots: bool,

0 commit comments

Comments
 (0)