@@ -15,6 +15,7 @@ use std::env;
15
15
use std:: fmt;
16
16
use std:: path:: { Path , PathBuf } ;
17
17
use std:: process:: Command ;
18
+ use std:: time:: { Duration , Instant } ;
18
19
use url:: Url ;
19
20
20
21
fn serialize_str < T , S > ( t : & T , s : S ) -> Result < S :: Ok , S :: Error >
@@ -694,12 +695,40 @@ pub fn with_fetch_options(
694
695
let mut progress = Progress :: new ( "Fetch" , config) ;
695
696
network:: with_retry ( config, || {
696
697
with_authentication ( url, git_config, |f| {
698
+ let mut last_recv = 0.0 ; // in Byte
699
+ let mut last_rate = 0.0 ; // in Byte/s
700
+ let mut last_update = Instant :: now ( ) ;
697
701
let mut rcb = git2:: RemoteCallbacks :: new ( ) ;
698
702
rcb. credentials ( f) ;
699
-
700
703
rcb. transfer_progress ( |stats| {
704
+ let indexed_deltas = stats. indexed_deltas ( ) ;
705
+ let msg = if indexed_deltas > 0 {
706
+ // Resolving deltas.
707
+ format ! ( " ({}/{})" , indexed_deltas, stats. total_deltas( ) )
708
+ } else {
709
+ // Receiving objects.
710
+ let duration = last_update. elapsed ( ) ;
711
+ let ( recv, rate) = if duration > Duration :: from_secs ( 1 ) {
712
+ let recv = stats. received_bytes ( ) as f32 ;
713
+ let rate = ( recv - last_recv) / duration. as_secs_f32 ( ) ;
714
+ last_recv = recv;
715
+ last_rate = rate;
716
+ last_update = Instant :: now ( ) ;
717
+ ( recv, rate)
718
+ } else {
719
+ ( last_recv, last_rate)
720
+ } ;
721
+ fn format_bytes ( bytes : f32 ) -> ( & ' static str , f32 ) {
722
+ static UNITS : [ & str ; 5 ] = [ "" , "K" , "M" , "G" , "T" ] ;
723
+ let i = ( bytes. log2 ( ) / 10.0 ) . min ( 4.0 ) as usize ;
724
+ ( UNITS [ i] , bytes / 1024_f32 . powi ( i as i32 ) )
725
+ }
726
+ let ( rate_unit, rate) = format_bytes ( rate) ;
727
+ let ( unit, recv) = format_bytes ( recv) ;
728
+ format ! ( " | {:.2}{}iB | {:.2}{}iB/s" , recv, unit, rate, rate_unit)
729
+ } ;
701
730
progress
702
- . tick ( stats. indexed_objects ( ) , stats. total_objects ( ) , "" )
731
+ . tick ( stats. indexed_objects ( ) , stats. total_objects ( ) , & msg )
703
732
. is_ok ( )
704
733
} ) ;
705
734
0 commit comments