@@ -151,30 +151,16 @@ impl GitDatabase {
151151 dest : & Path ,
152152 cargo_config : & Config ,
153153 ) -> CargoResult < GitCheckout < ' _ > > {
154- let mut checkout = None ;
155- if let Ok ( repo) = git2:: Repository :: open ( dest) {
156- let mut co = GitCheckout :: new ( dest, self , rev, repo) ;
157- if !co. is_fresh ( ) {
158- // After a successful fetch operation the subsequent reset can
159- // fail sometimes for corrupt repositories where the fetch
160- // operation succeeds but the object isn't actually there in one
161- // way or another. In these situations just skip the error and
162- // try blowing away the whole repository and trying with a
163- // clone.
164- co. fetch ( cargo_config) ?;
165- match co. reset ( cargo_config) {
166- Ok ( ( ) ) => {
167- assert ! ( co. is_fresh( ) ) ;
168- checkout = Some ( co) ;
169- }
170- Err ( e) => debug ! ( "failed reset after fetch {:?}" , e) ,
171- }
172- } else {
173- checkout = Some ( co) ;
174- }
175- } ;
176- let checkout = match checkout {
177- Some ( c) => c,
154+ // If the existing checkout exists, and it is fresh, use it.
155+ // A non-fresh checkout can happen if the checkout operation was
156+ // interrupted. In that case, the checkout gets deleted and a new
157+ // clone is created.
158+ let checkout = match git2:: Repository :: open ( dest)
159+ . ok ( )
160+ . map ( |repo| GitCheckout :: new ( dest, self , rev, repo) )
161+ . filter ( |co| co. is_fresh ( ) )
162+ {
163+ Some ( co) => co,
178164 None => GitCheckout :: clone_into ( dest, self , rev, cargo_config) ?,
179165 } ;
180166 checkout. update_submodules ( cargo_config) ?;
@@ -311,14 +297,6 @@ impl<'a> GitCheckout<'a> {
311297 }
312298 }
313299
314- fn fetch ( & mut self , cargo_config : & Config ) -> CargoResult < ( ) > {
315- info ! ( "fetch {}" , self . repo. path( ) . display( ) ) ;
316- let url = self . database . path . into_url ( ) ?;
317- let reference = GitReference :: Rev ( self . revision . to_string ( ) ) ;
318- fetch ( & mut self . repo , url. as_str ( ) , & reference, cargo_config) ?;
319- Ok ( ( ) )
320- }
321-
322300 fn reset ( & self , config : & Config ) -> CargoResult < ( ) > {
323301 // If we're interrupted while performing this reset (e.g., we die because
324302 // of a signal) Cargo needs to be sure to try to check out this repo
0 commit comments