got the revwalker working.

This commit is contained in:
Gabe Venberg 2024-02-14 14:42:26 -06:00
parent 0293018f85
commit dd63558560
5 changed files with 16 additions and 24 deletions

View file

@ -1,13 +1,9 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::err::GitErrors; use crate::err::GitErrors;
use chrono::prelude::*; use chrono::{prelude::*, NaiveDateTime};
use chrono::NaiveDateTime;
use chrono_tz::Tz; use chrono_tz::Tz;
use clap::Parser; use clap::Parser;
use git2::Commit; use git2::{Oid, Repository, Sort};
use git2::Oid;
use git2::Repository;
use git2::Sort;
use crate::time::DateTimeRange; use crate::time::DateTimeRange;
@ -34,6 +30,7 @@ pub(crate) struct Cli {
pub(crate) timezone: Option<chrono_tz::Tz>, pub(crate) timezone: Option<chrono_tz::Tz>,
} }
#[derive(Debug)]
pub(crate) struct ProgramOptions { pub(crate) struct ProgramOptions {
pub(crate) start_time: DateTime<Tz>, pub(crate) start_time: DateTime<Tz>,
pub(crate) end_time: DateTime<Tz>, pub(crate) end_time: DateTime<Tz>,
@ -83,15 +80,15 @@ impl TryFrom<Cli> for ProgramOptions {
let mut sorting = Sort::REVERSE; let mut sorting = Sort::REVERSE;
sorting.insert(Sort::TOPOLOGICAL); sorting.insert(Sort::TOPOLOGICAL);
sorting.insert(Sort::TIME); sorting.insert(Sort::TIME);
let mut revwalker = repo.revwalk().unwrap(); let mut revwalker = repo.revwalk().expect("could not construct revwalker");
revwalker.set_sorting(sorting).unwrap(); revwalker.push_head().expect("could not push head");
revwalker.simplify_first_parent().unwrap(); revwalker.set_sorting(sorting).expect("could not set revwalker sorting");
revwalker.next().unwrap().unwrap() revwalker.next().expect("revwalker is empty").expect("IDK what this error is")
}; };
Ok(ProgramOptions { Ok(ProgramOptions {
start_time, start_time,
end_time, end_time,
allowed_times: todo!(), allowed_times: Vec::new(),
first_commit, first_commit,
last_commit, last_commit,
}) })

View file

@ -1,4 +1,3 @@
#![allow(dead_code)]
use thiserror::Error; use thiserror::Error;
#[derive(Debug, Error)] #[derive(Debug, Error)]

View file

@ -24,7 +24,7 @@ pub fn rebase_commits_across_timerange<Tz: chrono::TimeZone>(
ranges: &[DateTimeRange<Tz>], ranges: &[DateTimeRange<Tz>],
max_jitter: &Duration, max_jitter: &Duration,
) -> Result<(), GitErrors> { ) -> Result<(), GitErrors> {
let num_commits = get_no_of_commits(&start_commit, &end_commit)?; let num_commits = get_no_of_commits(start_commit, end_commit)?;
let times = distribute_across_ranges_with_jitter(ranges, num_commits, max_jitter); let times = distribute_across_ranges_with_jitter(ranges, num_commits, max_jitter);
todo!() todo!()
} }

View file

@ -3,15 +3,11 @@ mod err;
mod git; mod git;
mod time; mod time;
use chrono::prelude::*;
use chrono_tz::Tz;
use clap::Parser; use clap::Parser;
use err::GitErrors;
fn main() { fn main() -> Result<(), GitErrors>{
let cli = args::Cli::parse(); let options: args::ProgramOptions = args::Cli::parse().try_into().unwrap();
println!("{:#?}", cli); println!("{:#?}", options);
println!( Ok(())
"start_time = {:#?}, end_time = {:#?}, tz = {:#?}",
start_time, end_time, tz
)
} }

View file

@ -17,8 +17,8 @@ impl<Tz: chrono::TimeZone> DateTimeRange<Tz> {
) -> Option<DateTimeRange<Tz>> { ) -> Option<DateTimeRange<Tz>> {
if self.is_in_range(&other.start) || self.is_in_range(&other.end) { if self.is_in_range(&other.start) || self.is_in_range(&other.end) {
Some(DateTimeRange { Some(DateTimeRange {
start: self.start.max(other.start), start: self.start.clone().max(other.start.clone()),
end: self.end.min(other.end), end: self.end.clone().min(other.end.clone()),
}) })
} else { } else {
None None