@@ -8,6 +8,7 @@ use std::time::Duration;
88use once_cell:: sync:: Lazy ;
99use regex:: Regex ;
1010use rustc_hash:: FxHashSet ;
11+ use wait_timeout:: ChildExt ;
1112
1213use crate :: config:: git:: { self , GIT } ;
1314use crate :: types:: DiffHunk ;
@@ -105,19 +106,12 @@ fn wait_with_timeout(
105106 } )
106107 } ) ;
107108
108- let start = std:: time:: Instant :: now ( ) ;
109- let status = loop {
110- match child. try_wait ( ) {
111- Ok ( Some ( status) ) => break status,
112- Ok ( None ) => {
113- if start. elapsed ( ) >= timeout {
114- let _ = child. kill ( ) ;
115- let _ = child. wait ( ) ;
116- return Err ( GitError :: Timeout ( timeout. as_secs ( ) ) ) ;
117- }
118- std:: thread:: sleep ( Duration :: from_millis ( GIT . poll_interval_ms ) ) ;
119- }
120- Err ( e) => return Err ( GitError :: Io ( e) ) ,
109+ let status = match child. wait_timeout ( timeout) ? {
110+ Some ( status) => status,
111+ None => {
112+ let _ = child. kill ( ) ;
113+ let _ = child. wait ( ) ;
114+ return Err ( GitError :: Timeout ( timeout. as_secs ( ) ) ) ;
121115 }
122116 } ;
123117
@@ -576,8 +570,8 @@ impl CatFileBatch {
576570 if let Some ( mut child) = self . child . take ( ) {
577571 drop ( child. stdin . take ( ) ) ;
578572 match child. wait_timeout ( Duration :: from_secs ( GIT . catfile_termination_timeout_seconds ) ) {
579- Ok ( _ ) => { }
580- Err ( _ ) => {
573+ Ok ( Some ( _ ) ) => { }
574+ _ => {
581575 let _ = child. kill ( ) ;
582576 let _ = child. wait ( ) ;
583577 }
@@ -591,25 +585,3 @@ impl Drop for CatFileBatch {
591585 self . close ( ) ;
592586 }
593587}
594-
595- trait WaitTimeout {
596- fn wait_timeout ( & mut self , dur : Duration ) -> std:: result:: Result < std:: process:: ExitStatus , ( ) > ;
597- }
598-
599- impl WaitTimeout for Child {
600- fn wait_timeout ( & mut self , dur : Duration ) -> std:: result:: Result < std:: process:: ExitStatus , ( ) > {
601- let start = std:: time:: Instant :: now ( ) ;
602- loop {
603- match self . try_wait ( ) {
604- Ok ( Some ( status) ) => return Ok ( status) ,
605- Ok ( None ) => {
606- if start. elapsed ( ) >= dur {
607- return Err ( ( ) ) ;
608- }
609- std:: thread:: sleep ( Duration :: from_millis ( GIT . poll_interval_ms ) ) ;
610- }
611- Err ( _) => return Err ( ( ) ) ,
612- }
613- }
614- }
615- }
0 commit comments