Skip to content

Commit

Permalink
Merge pull request #177 from ehuss/fixup-bounds
Browse files Browse the repository at this point in the history
Allow tag-like bounds that are older than 167 days.
  • Loading branch information
oli-obk authored Jul 29, 2022
2 parents 5eafc84 + 971bd2e commit 5f22e35
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,45 @@ impl Config {
}
}

/// Translates a tag-like bound (such as `1.62.0`) to a `Bound::Date` so that
/// bisecting works for versions older than 167 days.
fn fixup_bounds(
access: &Access,
start: &mut Option<Bound>,
end: &mut Option<Bound>,
) -> anyhow::Result<()> {
let is_tag = |bound: &Option<Bound>| -> bool {
match bound {
Some(Bound::Commit(commit)) => commit.contains('.'),
None | Some(Bound::Date(_)) => false,
}
};
let is_datelike = |bound: &Option<Bound>| -> bool {
matches!(bound, None | Some(Bound::Date(_))) || is_tag(bound)
};
if !(is_datelike(start) && is_datelike(end)) {
// If the user specified an actual commit for one bound, then don't
// even try to convert the other bound to a date.
return Ok(());
}
let fixup = |which: &str, bound: &mut Option<Bound>| -> anyhow::Result<()> {
if is_tag(bound) {
if let Some(Bound::Commit(tag)) = bound {
let date = access.repo().bound_to_date(Bound::Commit(tag.clone()))?;
eprintln!(
"translating --{which}={tag} to {date}",
date = date.format(YYYY_MM_DD)
);
*bound = Some(Bound::Date(date));
}
}
Ok(())
};
fixup("start", start)?;
fixup("end", end)?;
Ok(())
}

fn check_bounds(start: &Option<Bound>, end: &Option<Bound>) -> anyhow::Result<()> {
// current UTC date
let current = Utc::today();
Expand Down Expand Up @@ -519,7 +558,8 @@ fn check_bounds(start: &Option<Bound>, end: &Option<Bound>) -> anyhow::Result<()
// Application entry point
fn run() -> anyhow::Result<()> {
env_logger::try_init()?;
let args = Opts::parse();
let mut args = Opts::parse();
fixup_bounds(&args.access, &mut args.start, &mut args.end)?;
check_bounds(&args.start, &args.end)?;
let cfg = Config::from_args(args)?;

Expand Down

0 comments on commit 5f22e35

Please sign in to comment.