@@ -701,6 +701,23 @@ pub fn fetch(
701
701
url : & str ,
702
702
refspec : & str ,
703
703
config : & Config ,
704
+ ) -> CargoResult < ( ) > {
705
+ fetch_impl ( repo, url, refspec, config) ?;
706
+ // We reuse repositories quite a lot, so now that we have updated the repo,
707
+ // check to see if it's a little too old and could benefit from a gc.
708
+ // `git gc` goes through lengths to avoid removing precious data. In
709
+ // principle, we could be running it in the background while we're fetching,
710
+ // but better safe(r) than sorry, we just spawn it once we're done. It will
711
+ // be spawned in the background (so effectively, cargo will likely have
712
+ // terminated before `git gc` finishes), but only if necessary.
713
+ maybe_gc_repo ( repo)
714
+ }
715
+
716
+ fn fetch_impl (
717
+ repo : & mut git2:: Repository ,
718
+ url : & str ,
719
+ refspec : & str ,
720
+ config : & Config ,
704
721
) -> CargoResult < ( ) > {
705
722
if config. frozen ( ) {
706
723
anyhow:: bail!(
@@ -729,12 +746,6 @@ pub fn fetch(
729
746
}
730
747
}
731
748
732
- // We reuse repositories quite a lot, so before we go through and update the
733
- // repo check to see if it's a little too old and could benefit from a gc.
734
- // In theory this shouldn't be too too expensive compared to the network
735
- // request we're about to issue.
736
- maybe_gc_repo ( repo) ?;
737
-
738
749
// Unfortunately `libgit2` is notably lacking in the realm of authentication
739
750
// when compared to the `git` command line. As a result, allow an escape
740
751
// hatch for users that would prefer to use `git`-the-CLI for fetching
@@ -860,9 +871,7 @@ fn maybe_gc_repo(repo: &mut git2::Repository) -> CargoResult<()> {
860
871
}
861
872
Err ( e) => debug ! ( "git-gc failed to spawn: {}" , e) ,
862
873
}
863
-
864
- // Alright all else failed, let's start over.
865
- reinitialize ( repo)
874
+ Ok ( ( ) )
866
875
}
867
876
868
877
fn reinitialize ( repo : & mut git2:: Repository ) -> CargoResult < ( ) > {
0 commit comments