@@ -9,7 +9,7 @@ use crate::util::errors::CargoResult;
99use crate :: util:: interning:: InternedString ;
1010use crate :: util:: { Config , Filesystem } ;
1111use anyhow:: Context as _;
12- use cargo_util:: { paths, Sha256 } ;
12+ use cargo_util:: { paths, registry :: make_dep_path , Sha256 } ;
1313use lazycell:: LazyCell ;
1414use log:: { debug, trace} ;
1515use std:: cell:: { Cell , Ref , RefCell } ;
@@ -21,15 +21,6 @@ use std::mem;
2121use std:: path:: Path ;
2222use std:: str;
2323
24- fn make_dep_prefix ( name : & str ) -> String {
25- match name. len ( ) {
26- 1 => String :: from ( "1" ) ,
27- 2 => String :: from ( "2" ) ,
28- 3 => format ! ( "3/{}" , & name[ ..1 ] ) ,
29- _ => format ! ( "{}/{}" , & name[ 0 ..2 ] , & name[ 2 ..4 ] ) ,
30- }
31- }
32-
3324/// A remote registry is a registry that lives at a remote URL (such as
3425/// crates.io). The git index is cloned locally, and `.crate` files are
3526/// downloaded as needed and cached locally.
@@ -279,7 +270,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
279270 {
280271 write ! ( url, "/{}/{}/download" , CRATE_TEMPLATE , VERSION_TEMPLATE ) . unwrap ( ) ;
281272 }
282- let prefix = make_dep_prefix ( & * pkg. name ( ) ) ;
273+ let prefix = make_dep_path ( & * pkg. name ( ) , true ) ;
283274 let url = url
284275 . replace ( CRATE_TEMPLATE , & * pkg. name ( ) )
285276 . replace ( VERSION_TEMPLATE , & pkg. version ( ) . to_string ( ) )
@@ -343,18 +334,3 @@ impl<'cfg> Drop for RemoteRegistry<'cfg> {
343334 self . tree . borrow_mut ( ) . take ( ) ;
344335 }
345336}
346-
347- #[ cfg( test) ]
348- mod tests {
349- use super :: make_dep_prefix;
350-
351- #[ test]
352- fn dep_prefix ( ) {
353- assert_eq ! ( make_dep_prefix( "a" ) , "1" ) ;
354- assert_eq ! ( make_dep_prefix( "ab" ) , "2" ) ;
355- assert_eq ! ( make_dep_prefix( "abc" ) , "3/a" ) ;
356- assert_eq ! ( make_dep_prefix( "Abc" ) , "3/A" ) ;
357- assert_eq ! ( make_dep_prefix( "AbCd" ) , "Ab/Cd" ) ;
358- assert_eq ! ( make_dep_prefix( "aBcDe" ) , "aB/cD" ) ;
359- }
360- }
0 commit comments