@@ -2,7 +2,7 @@ use crate::{
2
2
cli:: NumberSeparator ,
3
3
info:: utils:: { format_number, info_field:: InfoField } ,
4
4
} ;
5
- use byte_unit:: Byte ;
5
+ use byte_unit:: { Byte , UnitType } ;
6
6
use gix:: Repository ;
7
7
use serde:: Serialize ;
8
8
@@ -29,7 +29,7 @@ impl SizeInfo {
29
29
fn get_repo_size ( repo : & Repository ) -> ( String , u64 ) {
30
30
let ( repo_size, file_count) = match repo. index ( ) {
31
31
Ok ( index) => {
32
- let repo_size = index. entries ( ) . iter ( ) . map ( |e| e. stat . size as u128 ) . sum ( ) ;
32
+ let repo_size = index. entries ( ) . iter ( ) . map ( |e| e. stat . size as u64 ) . sum ( ) ;
33
33
( repo_size, index. entries ( ) . len ( ) as u64 )
34
34
}
35
35
_ => ( 0 , 0 ) ,
@@ -38,9 +38,9 @@ fn get_repo_size(repo: &Repository) -> (String, u64) {
38
38
( bytes_to_human_readable ( repo_size) , file_count)
39
39
}
40
40
41
- fn bytes_to_human_readable ( bytes : u128 ) -> String {
42
- let byte = Byte :: from_bytes ( bytes) ;
43
- byte. get_appropriate_unit ( true ) . to_string ( )
41
+ fn bytes_to_human_readable ( bytes : u64 ) -> String {
42
+ let byte = Byte :: from_u64 ( bytes) ;
43
+ byte. get_appropriate_unit ( UnitType :: Binary ) . to_string ( )
44
44
}
45
45
46
46
impl std:: fmt:: Display for SizeInfo {
@@ -72,6 +72,8 @@ impl InfoField for SizeInfo {
72
72
73
73
#[ cfg( test) ]
74
74
mod test {
75
+ use rstest:: rstest;
76
+
75
77
use super :: * ;
76
78
77
79
#[ test]
@@ -106,4 +108,17 @@ mod test {
106
108
107
109
assert_eq ! ( size_info. value( ) , "2.40 MiB (1 file)" . to_string( ) ) ;
108
110
}
111
+
112
+ #[ rstest(
113
+ case( 0 , "0 B" ) ,
114
+ case( 1023 , "1023 B" ) ,
115
+ case( 1024 , "1 KiB" ) ,
116
+ case( 2048 , "2 KiB" ) ,
117
+ case( 1048576 , "1 MiB" ) ,
118
+ case( 1099511627776 , "1 TiB" ) ,
119
+ // Add more test cases as needed
120
+ ) ]
121
+ fn test_bytes_to_human_readable ( #[ case] input : u64 , #[ case] expected : & str ) {
122
+ assert_eq ! ( bytes_to_human_readable( input) , expected) ;
123
+ }
109
124
}
0 commit comments