@@ -2,7 +2,7 @@ use crate::{
22 cli:: NumberSeparator ,
33 info:: utils:: { format_number, info_field:: InfoField } ,
44} ;
5- use byte_unit:: Byte ;
5+ use byte_unit:: { Byte , UnitType } ;
66use gix:: Repository ;
77use serde:: Serialize ;
88
@@ -29,7 +29,7 @@ impl SizeInfo {
2929fn get_repo_size ( repo : & Repository ) -> ( String , u64 ) {
3030 let ( repo_size, file_count) = match repo. index ( ) {
3131 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 ( ) ;
3333 ( repo_size, index. entries ( ) . len ( ) as u64 )
3434 }
3535 _ => ( 0 , 0 ) ,
@@ -38,9 +38,9 @@ fn get_repo_size(repo: &Repository) -> (String, u64) {
3838 ( bytes_to_human_readable ( repo_size) , file_count)
3939}
4040
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 ( )
4444}
4545
4646impl std:: fmt:: Display for SizeInfo {
@@ -72,6 +72,8 @@ impl InfoField for SizeInfo {
7272
7373#[ cfg( test) ]
7474mod test {
75+ use rstest:: rstest;
76+
7577 use super :: * ;
7678
7779 #[ test]
@@ -106,4 +108,17 @@ mod test {
106108
107109 assert_eq ! ( size_info. value( ) , "2.40 MiB (1 file)" . to_string( ) ) ;
108110 }
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+ }
109124}
0 commit comments