@@ -869,6 +869,66 @@ fn bisect(cfg: &Config, client: &Client) -> Result<(), Error> {
869869 Ok ( ( ) )
870870}
871871
872+ struct NightlyFinderIter {
873+ start_date : Date < Utc > ,
874+ current_date : Date < Utc > ,
875+ }
876+
877+ impl NightlyFinderIter {
878+ fn new ( start_date : Date < Utc > ) -> Self {
879+ Self {
880+ start_date,
881+ current_date : start_date,
882+ }
883+ }
884+ }
885+
886+ impl Iterator for NightlyFinderIter {
887+ type Item = Date < Utc > ;
888+
889+ fn next ( & mut self ) -> Option < Date < Utc > > {
890+ let current_distance = self . start_date - self . current_date ;
891+
892+ let jump_length =
893+ if current_distance. num_days ( ) < 7 {
894+ // first week jump by two days
895+ 2
896+ } else if current_distance. num_days ( ) < 49 {
897+ // from 2nd to 7th week jump weekly
898+ 7
899+ } else {
900+ // from 7th week jump by two weeks
901+ 14
902+ } ;
903+
904+ self . current_date = self . current_date - chrono:: Duration :: days ( jump_length) ;
905+ Some ( self . current_date )
906+ }
907+ }
908+
909+ #[ test]
910+ fn test_nightly_finder_iterator ( ) {
911+ let start_date = chrono:: Date :: from_utc (
912+ chrono:: naive:: NaiveDate :: from_ymd ( 2019 , 01 , 01 ) ,
913+ chrono:: Utc ,
914+ ) ;
915+
916+ let mut iter = NightlyFinderIter :: new ( start_date) ;
917+
918+ assert_eq ! ( start_date - chrono:: Duration :: days( 2 ) , iter. next( ) . unwrap( ) ) ;
919+ assert_eq ! ( start_date - chrono:: Duration :: days( 4 ) , iter. next( ) . unwrap( ) ) ;
920+ assert_eq ! ( start_date - chrono:: Duration :: days( 6 ) , iter. next( ) . unwrap( ) ) ;
921+ assert_eq ! ( start_date - chrono:: Duration :: days( 8 ) , iter. next( ) . unwrap( ) ) ;
922+ assert_eq ! ( start_date - chrono:: Duration :: days( 15 ) , iter. next( ) . unwrap( ) ) ;
923+ assert_eq ! ( start_date - chrono:: Duration :: days( 22 ) , iter. next( ) . unwrap( ) ) ;
924+ assert_eq ! ( start_date - chrono:: Duration :: days( 29 ) , iter. next( ) . unwrap( ) ) ;
925+ assert_eq ! ( start_date - chrono:: Duration :: days( 36 ) , iter. next( ) . unwrap( ) ) ;
926+ assert_eq ! ( start_date - chrono:: Duration :: days( 43 ) , iter. next( ) . unwrap( ) ) ;
927+ assert_eq ! ( start_date - chrono:: Duration :: days( 50 ) , iter. next( ) . unwrap( ) ) ;
928+ assert_eq ! ( start_date - chrono:: Duration :: days( 64 ) , iter. next( ) . unwrap( ) ) ;
929+ assert_eq ! ( start_date - chrono:: Duration :: days( 78 ) , iter. next( ) . unwrap( ) ) ;
930+ }
931+
872932fn bisect_nightlies ( cfg : & Config , client : & Client ) -> Result < BisectionResult , Error > {
873933 if cfg. args . alt {
874934 bail ! ( "cannot bisect nightlies with --alt: not supported" ) ;
@@ -883,7 +943,6 @@ fn bisect_nightlies(cfg: &Config, client: &Client) -> Result<BisectionResult, Er
883943 ( today, false )
884944 } ;
885945
886- let mut jump_length = 1 ;
887946 // before this date we didn't have -std packages
888947 let end_at = chrono:: Date :: from_utc (
889948 chrono:: naive:: NaiveDate :: from_ymd ( 2015 , 10 , 20 ) ,
@@ -905,6 +964,8 @@ fn bisect_nightlies(cfg: &Config, client: &Client) -> Result<BisectionResult, Er
905964 }
906965 } ;
907966
967+ let mut nightly_iter = NightlyFinderIter :: new ( nightly_date) ;
968+
908969 while nightly_date > end_at {
909970 let mut t = Toolchain {
910971 spec : ToolchainSpec :: Nightly { date : nightly_date } ,
@@ -930,10 +991,9 @@ fn bisect_nightlies(cfg: &Config, client: &Client) -> Result<BisectionResult, Er
930991 } else {
931992 last_failure = nightly_date;
932993 }
933- nightly_date = nightly_date - chrono:: Duration :: days ( jump_length) ;
934- if jump_length < 30 {
935- jump_length *= 2 ;
936- }
994+
995+ nightly_date = nightly_iter. next ( ) . unwrap ( ) ;
996+
937997 if !cfg. args . preserve {
938998 let _ = t. remove ( & dl_spec) ;
939999 }
0 commit comments