Skip to content

Commit 4ec0356

Browse files
committed
Allow tag-like bounds that are older than 167 days.
1 parent 5eafc84 commit 4ec0356

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/main.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,42 @@ impl Config {
484484
}
485485
}
486486

487+
/// Translates a tag-like bound (such as `1.62.0`) to a `Bound::Date` so that
488+
/// bisecting works for versions older than 167 days.
489+
fn fixup_bounds(
490+
access: &Access,
491+
start: &mut Option<Bound>,
492+
end: &mut Option<Bound>,
493+
) -> anyhow::Result<()> {
494+
let is_tag = |bound: &Option<Bound>| -> bool {
495+
match bound {
496+
Some(Bound::Commit(commit)) => commit.contains('.'),
497+
None | Some(Bound::Date(_)) => false,
498+
}
499+
};
500+
let is_datelike = |bound: &Option<Bound>| -> bool {
501+
matches!(bound, None | Some(Bound::Date(_))) || is_tag(bound)
502+
};
503+
if !(is_datelike(start) && is_datelike(end)) {
504+
// If the user specified an actual commit for one bound, then don't
505+
// even try to convert the other bound to a date.
506+
return Ok(());
507+
}
508+
let fixup = |bound: &mut Option<Bound>| -> anyhow::Result<()> {
509+
if is_tag(bound) {
510+
if let Some(b) = bound.clone() {
511+
if is_tag(bound) {
512+
*bound = Some(Bound::Date(access.repo().bound_to_date(b)?));
513+
}
514+
}
515+
}
516+
Ok(())
517+
};
518+
fixup(start)?;
519+
fixup(end)?;
520+
Ok(())
521+
}
522+
487523
fn check_bounds(start: &Option<Bound>, end: &Option<Bound>) -> anyhow::Result<()> {
488524
// current UTC date
489525
let current = Utc::today();
@@ -519,7 +555,8 @@ fn check_bounds(start: &Option<Bound>, end: &Option<Bound>) -> anyhow::Result<()
519555
// Application entry point
520556
fn run() -> anyhow::Result<()> {
521557
env_logger::try_init()?;
522-
let args = Opts::parse();
558+
let mut args = Opts::parse();
559+
fixup_bounds(&args.access, &mut args.start, &mut args.end)?;
523560
check_bounds(&args.start, &args.end)?;
524561
let cfg = Config::from_args(args)?;
525562

0 commit comments

Comments
 (0)