@@ -484,6 +484,45 @@ 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 = |which : & str , bound : & mut Option < Bound > | -> anyhow:: Result < ( ) > {
509+ if is_tag ( bound) {
510+ if let Some ( Bound :: Commit ( tag) ) = bound {
511+ let date = access. repo ( ) . bound_to_date ( Bound :: Commit ( tag. clone ( ) ) ) ?;
512+ eprintln ! (
513+ "translating --{which}={tag} to {date}" ,
514+ date = date. format( YYYY_MM_DD )
515+ ) ;
516+ * bound = Some ( Bound :: Date ( date) ) ;
517+ }
518+ }
519+ Ok ( ( ) )
520+ } ;
521+ fixup ( "start" , start) ?;
522+ fixup ( "end" , end) ?;
523+ Ok ( ( ) )
524+ }
525+
487526fn check_bounds ( start : & Option < Bound > , end : & Option < Bound > ) -> anyhow:: Result < ( ) > {
488527 // current UTC date
489528 let current = Utc :: today ( ) ;
@@ -519,7 +558,8 @@ fn check_bounds(start: &Option<Bound>, end: &Option<Bound>) -> anyhow::Result<()
519558// Application entry point
520559fn run ( ) -> anyhow:: Result < ( ) > {
521560 env_logger:: try_init ( ) ?;
522- let args = Opts :: parse ( ) ;
561+ let mut args = Opts :: parse ( ) ;
562+ fixup_bounds ( & args. access , & mut args. start , & mut args. end ) ?;
523563 check_bounds ( & args. start , & args. end ) ?;
524564 let cfg = Config :: from_args ( args) ?;
525565
0 commit comments