Skip to content

Commit 202eb1d

Browse files
committed
Auto merge of #12203 - weihanglo:make-dep-prefix, r=epage
refactor: de-depulicate `make_dep_prefix` implementation
2 parents c9b89c6 + ae17f2c commit 202eb1d

File tree

1 file changed

+3
-21
lines changed
  • src/cargo/sources/registry

1 file changed

+3
-21
lines changed

src/cargo/sources/registry/mod.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -1013,26 +1013,8 @@ fn max_unpack_size(config: &Config, size: u64) -> u64 {
10131013
u64::max(max_unpack_size, size * max_compression_ratio as u64)
10141014
}
10151015

1016+
/// Constructs a path to a dependency in the registry index on filesystem.
1017+
/// See [`cargo_util::registry::make_dep_path`] for more.
10161018
fn make_dep_prefix(name: &str) -> String {
1017-
match name.len() {
1018-
1 => String::from("1"),
1019-
2 => String::from("2"),
1020-
3 => format!("3/{}", &name[..1]),
1021-
_ => format!("{}/{}", &name[0..2], &name[2..4]),
1022-
}
1023-
}
1024-
1025-
#[cfg(test)]
1026-
mod tests {
1027-
use super::make_dep_prefix;
1028-
1029-
#[test]
1030-
fn dep_prefix() {
1031-
assert_eq!(make_dep_prefix("a"), "1");
1032-
assert_eq!(make_dep_prefix("ab"), "2");
1033-
assert_eq!(make_dep_prefix("abc"), "3/a");
1034-
assert_eq!(make_dep_prefix("Abc"), "3/A");
1035-
assert_eq!(make_dep_prefix("AbCd"), "Ab/Cd");
1036-
assert_eq!(make_dep_prefix("aBcDe"), "aB/cD");
1037-
}
1019+
cargo_util::registry::make_dep_path(name, true)
10381020
}

0 commit comments

Comments
 (0)