@@ -30,7 +30,7 @@ use rustc_serialize::Decodable;
30
30
use rustc_serialize:: json;
31
31
32
32
use curl:: easy:: Easy ;
33
- use git2:: { Repository , Cred } ;
33
+ use git2:: { Repository , Cred , CredentialType } ;
34
34
use sha2:: { Digest , Sha256 } ;
35
35
use clap:: { App , Arg } ;
36
36
@@ -44,7 +44,14 @@ use router::Router;
44
44
#[ derive( Debug , RustcDecodable , Clone ) ]
45
45
struct GitConfig {
46
46
upstream_url : String ,
47
- origin_url : Option < String > ,
47
+ origin : Option < OriginConfig > ,
48
+ }
49
+
50
+ #[ derive( Debug , RustcDecodable , Clone ) ]
51
+ struct OriginConfig {
52
+ url : String ,
53
+ username : Option < String > ,
54
+ password : Option < String > ,
48
55
}
49
56
50
57
#[ derive( Debug , RustcDecodable , Clone ) ]
@@ -344,10 +351,11 @@ fn main() {
344
351
. unwrap ( ) ;
345
352
346
353
347
- if let Some ( remote) = config. registry_config . origin_url . clone ( ) {
354
+ if let Some ( ref remote) = config. registry_config . origin {
348
355
let mut callbacks = git2:: RemoteCallbacks :: new ( ) ;
349
- callbacks. credentials ( credentials) ;
350
- repo. remote ( "local" , & remote) . unwrap ( ) ;
356
+ callbacks. credentials ( |url, user, cred| credentials ( url, user, cred, remote) ) ;
357
+ callbacks. transfer_progress ( progress_monitor) ;
358
+ repo. remote ( "local" , & remote. url ) . unwrap ( ) ;
351
359
let mut remote = repo. find_remote ( "local" ) . unwrap ( ) ;
352
360
let mut opts = git2:: PushOptions :: new ( ) ;
353
361
opts. remote_callbacks ( callbacks) ;
@@ -381,7 +389,8 @@ fn main() {
381
389
debug ! ( "startup finished" ) ;
382
390
println ! ( "finish to setup crates.io mirror. Point cargo repository to {}" ,
383
391
config. registry_config
384
- . origin_url
392
+ . origin
393
+ . map( |o| o. url)
385
394
. clone( )
386
395
. unwrap_or( format!( "file://{}" , base_dir. to_str( ) . unwrap( ) ) ) ) ;
387
396
@@ -390,6 +399,14 @@ fn main() {
390
399
. unwrap ( ) ;
391
400
}
392
401
402
+ fn progress_monitor ( progress : git2:: Progress ) -> bool {
403
+ debug ! ( "total :{}, local: {}, remote: {}" ,
404
+ progress. total_objects( ) ,
405
+ progress. local_objects( ) ,
406
+ progress. received_objects( ) ) ;
407
+ true
408
+ }
409
+
393
410
394
411
fn credentials ( url : & str ,
395
412
user_from_url : Option < & str > ,
@@ -493,17 +510,18 @@ fn try_merge(repo: &Repository,
493
510
let sig = try!( repo. signature ( ) ) ;
494
511
try!( repo. commit ( Some ( "HEAD" ) , & sig, & sig, "Merge" , & tree, & [ & parent] ) ) ;
495
512
496
- if let Some ( _ ) = config. registry_config . origin_url {
513
+ if let Some ( ref remote ) = config. registry_config . origin {
497
514
let mut callbacks = git2:: RemoteCallbacks :: new ( ) ;
498
- callbacks. credentials ( credentials) ;
515
+ callbacks. credentials ( |url, user, cred| credentials ( url, user, cred, remote) ) ;
516
+ callbacks. transfer_progress ( progress_monitor) ;
499
517
let mut remote = try!( repo. find_remote ( "local" ) ) ;
500
518
let mut opts = git2:: PushOptions :: new ( ) ;
501
519
opts. remote_callbacks ( callbacks) ;
502
520
try!( remote. push ( & [ "refs/heads/master" ] , Some ( & mut opts) ) ) ;
503
521
}
504
522
debug ! ( "updated index" ) ;
505
523
} else {
506
- debug ! ( "Nothing to update" ) ;
524
+ trace ! ( "Nothing to update" ) ;
507
525
try!( repo. cleanup_state ( ) ) ;
508
526
}
509
527
Ok ( ( ) )
0 commit comments