Skip to content

Commit

Permalink
use rev-specs instead of ref-names
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 19, 2022
1 parent 429cccc commit cf7182e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
20 changes: 5 additions & 15 deletions gitoxide-core/src/hours.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use std::{
collections::{hash_map::Entry, HashMap},
ffi::OsStr,
io,
path::Path,
time::Instant,
};

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::*;
Expand All @@ -41,7 +39,7 @@ pub struct Context<W> {
/// * _progress_ - A way to provide progress and performance information
pub fn estimate<W, P>(
working_dir: &Path,
refname: &OsStr,
rev_spec: &BStr,
mut progress: P,
Context {
show_pii,
Expand All @@ -55,23 +53,15 @@ 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();
let mut progress = progress.add_child("Traverse commit graph");
progress.init(None, progress::count("commits"));
let mut commits: Vec<Vec<u8>> = 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());
Expand Down
4 changes: 2 additions & 2 deletions src/porcelain/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions src/porcelain/options.rs
Original file line number Diff line number Diff line change
@@ -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!())]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit cf7182e

Please sign in to comment.