Skip to content

Commit

Permalink
refactor: de-depulicate make_dep_prefix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed May 30, 2023
1 parent c9b89c6 commit ae17f2c
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,26 +1013,8 @@ fn max_unpack_size(config: &Config, size: u64) -> u64 {
u64::max(max_unpack_size, size * max_compression_ratio as u64)
}

/// Constructs a path to a dependency in the registry index on filesystem.
/// See [`cargo_util::registry::make_dep_path`] for more.
fn make_dep_prefix(name: &str) -> String {
match name.len() {
1 => String::from("1"),
2 => String::from("2"),
3 => format!("3/{}", &name[..1]),
_ => format!("{}/{}", &name[0..2], &name[2..4]),
}
}

#[cfg(test)]
mod tests {
use super::make_dep_prefix;

#[test]
fn dep_prefix() {
assert_eq!(make_dep_prefix("a"), "1");
assert_eq!(make_dep_prefix("ab"), "2");
assert_eq!(make_dep_prefix("abc"), "3/a");
assert_eq!(make_dep_prefix("Abc"), "3/A");
assert_eq!(make_dep_prefix("AbCd"), "Ab/Cd");
assert_eq!(make_dep_prefix("aBcDe"), "aB/cD");
}
cargo_util::registry::make_dep_path(name, true)
}

0 comments on commit ae17f2c

Please sign in to comment.