@@ -141,7 +141,7 @@ impl GitRemote {
141
141
fn fetch_into ( & self , dst : & mut git2:: Repository , cargo_config : & Config ) -> CargoResult < ( ) > {
142
142
// Create a local anonymous remote in the repository to fetch the url
143
143
let refspec = "refs/heads/*:refs/heads/*" ;
144
- fetch ( dst, & self . url , refspec, cargo_config)
144
+ fetch ( dst, & self . url . as_str ( ) , refspec, cargo_config)
145
145
}
146
146
147
147
fn clone_into ( & self , dst : & Path , cargo_config : & Config ) -> CargoResult < git2:: Repository > {
@@ -152,7 +152,7 @@ impl GitRemote {
152
152
let mut repo = init ( dst, true ) ?;
153
153
fetch (
154
154
& mut repo,
155
- & self . url ,
155
+ & self . url . as_str ( ) ,
156
156
"refs/heads/*:refs/heads/*" ,
157
157
cargo_config,
158
158
) ?;
@@ -276,7 +276,7 @@ impl<'a> GitCheckout<'a> {
276
276
// need authentication information we may want progress bars and such.
277
277
let url = database. path . into_url ( ) ?;
278
278
let mut repo = None ;
279
- with_fetch_options ( & git_config, & url, config, & mut |fopts| {
279
+ with_fetch_options ( & git_config, url. as_str ( ) , config, & mut |fopts| {
280
280
let mut checkout = git2:: build:: CheckoutBuilder :: new ( ) ;
281
281
checkout. dry_run ( ) ; // we'll do this below during a `reset`
282
282
@@ -312,7 +312,7 @@ impl<'a> GitCheckout<'a> {
312
312
info ! ( "fetch {}" , self . repo. path( ) . display( ) ) ;
313
313
let url = self . database . path . into_url ( ) ?;
314
314
let refspec = "refs/heads/*:refs/heads/*" ;
315
- fetch ( & mut self . repo , & url, refspec, cargo_config) ?;
315
+ fetch ( & mut self . repo , url. as_str ( ) , refspec, cargo_config) ?;
316
316
Ok ( ( ) )
317
317
}
318
318
@@ -393,10 +393,8 @@ impl<'a> GitCheckout<'a> {
393
393
init ( & path, false ) ?
394
394
}
395
395
} ;
396
-
397
396
// Fetch data from origin and reset to the head commit
398
397
let refspec = "refs/heads/*:refs/heads/*" ;
399
- let url = url. into_url ( ) ?;
400
398
fetch ( & mut repo, & url, refspec, cargo_config) . chain_err ( || {
401
399
internal ( format ! (
402
400
"failed to fetch submodule `{}` from {}" ,
@@ -640,13 +638,13 @@ fn reset(repo: &git2::Repository, obj: &git2::Object<'_>, config: &Config) -> Ca
640
638
641
639
pub fn with_fetch_options (
642
640
git_config : & git2:: Config ,
643
- url : & Url ,
641
+ url : & str ,
644
642
config : & Config ,
645
643
cb : & mut dyn FnMut ( git2:: FetchOptions < ' _ > ) -> CargoResult < ( ) > ,
646
644
) -> CargoResult < ( ) > {
647
645
let mut progress = Progress :: new ( "Fetch" , config) ;
648
646
network:: with_retry ( config, || {
649
- with_authentication ( url. as_str ( ) , git_config, |f| {
647
+ with_authentication ( url, git_config, |f| {
650
648
let mut rcb = git2:: RemoteCallbacks :: new ( ) ;
651
649
rcb. credentials ( f) ;
652
650
@@ -669,7 +667,7 @@ pub fn with_fetch_options(
669
667
670
668
pub fn fetch (
671
669
repo : & mut git2:: Repository ,
672
- url : & Url ,
670
+ url : & str ,
673
671
refspec : & str ,
674
672
config : & Config ,
675
673
) -> CargoResult < ( ) > {
@@ -685,14 +683,17 @@ pub fn fetch(
685
683
686
684
// If we're fetching from GitHub, attempt GitHub's special fast path for
687
685
// testing if we've already got an up-to-date copy of the repository
688
- if url. host_str ( ) == Some ( "github.com" ) {
689
- if let Ok ( oid) = repo. refname_to_id ( "refs/remotes/origin/master" ) {
690
- let mut handle = config. http ( ) ?. borrow_mut ( ) ;
691
- debug ! ( "attempting GitHub fast path for {}" , url) ;
692
- if github_up_to_date ( & mut handle, url, & oid) {
693
- return Ok ( ( ) ) ;
694
- } else {
695
- debug ! ( "fast path failed, falling back to a git fetch" ) ;
686
+
687
+ if let Ok ( url) = Url :: parse ( url) {
688
+ if url. host_str ( ) == Some ( "github.com" ) {
689
+ if let Ok ( oid) = repo. refname_to_id ( "refs/remotes/origin/master" ) {
690
+ let mut handle = config. http ( ) ?. borrow_mut ( ) ;
691
+ debug ! ( "attempting GitHub fast path for {}" , url) ;
692
+ if github_up_to_date ( & mut handle, & url, & oid) {
693
+ return Ok ( ( ) ) ;
694
+ } else {
695
+ debug ! ( "fast path failed, falling back to a git fetch" ) ;
696
+ }
696
697
}
697
698
}
698
699
}
@@ -732,7 +733,7 @@ pub fn fetch(
732
733
loop {
733
734
debug ! ( "initiating fetch of {} from {}" , refspec, url) ;
734
735
let res = repo
735
- . remote_anonymous ( url. as_str ( ) ) ?
736
+ . remote_anonymous ( url) ?
736
737
. fetch ( & [ refspec] , Some ( & mut opts) , None ) ;
737
738
let err = match res {
738
739
Ok ( ( ) ) => break ,
@@ -759,7 +760,7 @@ pub fn fetch(
759
760
760
761
fn fetch_with_cli (
761
762
repo : & mut git2:: Repository ,
762
- url : & Url ,
763
+ url : & str ,
763
764
refspec : & str ,
764
765
config : & Config ,
765
766
) -> CargoResult < ( ) > {
@@ -768,7 +769,7 @@ fn fetch_with_cli(
768
769
. arg ( "--tags" ) // fetch all tags
769
770
. arg ( "--force" ) // handle force pushes
770
771
. arg ( "--update-head-ok" ) // see discussion in #2078
771
- . arg ( url. to_string ( ) )
772
+ . arg ( url)
772
773
. arg ( refspec)
773
774
// If cargo is run by git (for example, the `exec` command in `git
774
775
// rebase`), the GIT_DIR is set by git and will point to the wrong
0 commit comments