Skip to content

Commit 4a5da46

Browse files
Bump byte-unit from 4.0.19 to 5.0.3 (#1220)
* Bump byte-unit from 4.0.19 to 5.0.3 Bumps [byte-unit](https://github.com/magiclen/byte-unit) from 4.0.19 to 5.0.3. - [Commits](magiclen/Byte-Unit@v4.0.19...v5.0.3) --- updated-dependencies: - dependency-name: byte-unit dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * fix * bump --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: o2sh <[email protected]>
1 parent 70fc8d5 commit 4a5da46

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

Cargo.lock

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ strum = { version = "0.25.0", features = ["derive"] }
3232
[dependencies]
3333
anyhow.workspace = true
3434
askalono = "0.4.6"
35-
byte-unit = "4.0.19"
35+
byte-unit = "5.0.3"
3636
bytecount = "0.6.7"
3737
clap.workspace = true
3838
clap_complete = "4.4.4"

src/info/size.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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};
66
use gix::Repository;
77
use serde::Serialize;
88

@@ -29,7 +29,7 @@ impl SizeInfo {
2929
fn 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

4646
impl std::fmt::Display for SizeInfo {
@@ -72,6 +72,8 @@ impl InfoField for SizeInfo {
7272

7373
#[cfg(test)]
7474
mod 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

Comments
 (0)