11use crate :: {
2- db:: types:: { BuildStatus , Feature , version:: Version } ,
2+ db:: types:: {
3+ BuildId , BuildStatus , CrateId , Feature , ReleaseId , dependencies:: ReleaseDependencyList ,
4+ version:: Version ,
5+ } ,
36 docbuilder:: DocCoverage ,
47 error:: Result ,
58 registry_api:: { CrateData , CrateOwner , ReleaseData } ,
69 storage:: CompressionAlgorithm ,
7- utils:: { Dependency , MetadataPackage , rustc_version:: parse_rustc_date} ,
10+ utils:: { MetadataPackage , rustc_version:: parse_rustc_date} ,
811 web:: crate_details:: { latest_release, releases_for_crate} ,
912} ;
1013use anyhow:: { Context , anyhow} ;
11- use derive_more:: { Deref , Display } ;
1214use futures_util:: stream:: TryStreamExt ;
13- use semver:: VersionReq ;
14- use serde:: { Deserialize , Serialize } ;
1515use serde_json:: Value ;
1616use slug:: slugify;
1717use std:: {
@@ -22,56 +22,6 @@ use std::{
2222} ;
2323use tracing:: { debug, error, info, instrument} ;
2424
25- #[ derive( Debug , Clone , Copy , Display , PartialEq , Eq , Hash , Serialize , sqlx:: Type ) ]
26- #[ sqlx( transparent) ]
27- pub struct CrateId ( pub i32 ) ;
28-
29- #[ derive( Debug , Clone , Copy , Display , PartialEq , Eq , Hash , Serialize , sqlx:: Type ) ]
30- #[ sqlx( transparent) ]
31- pub struct ReleaseId ( pub i32 ) ;
32-
33- #[ derive( Debug , Clone , Copy , Display , PartialEq , Eq , Hash , Serialize , sqlx:: Type ) ]
34- #[ sqlx( transparent) ]
35- pub struct BuildId ( pub i32 ) ;
36-
37- type DepOut = ( String , String , String , bool ) ;
38- type DepIn = ( String , VersionReq , Option < String > , Option < bool > ) ;
39-
40- /// A crate dependency in our internal representation for releases.dependencies json.
41- #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Deref ) ]
42- #[ serde( from = "DepIn" , into = "DepOut" ) ]
43- pub ( crate ) struct ReleaseDependency ( Dependency ) ;
44-
45- impl ReleaseDependency {
46- pub ( crate ) fn into_inner ( self ) -> Dependency {
47- self . 0
48- }
49- }
50-
51- impl From < DepIn > for ReleaseDependency {
52- fn from ( ( name, req, kind, optional) : DepIn ) -> Self {
53- ReleaseDependency ( Dependency {
54- name,
55- req,
56- kind,
57- optional : optional. unwrap_or ( false ) ,
58- rename : None ,
59- } )
60- }
61- }
62-
63- impl From < ReleaseDependency > for DepOut {
64- fn from ( rd : ReleaseDependency ) -> Self {
65- let d = rd. 0 ;
66- (
67- d. name ,
68- d. req . to_string ( ) ,
69- d. kind . unwrap_or_else ( || "normal" . into ( ) ) ,
70- d. optional ,
71- )
72- }
73- }
74-
7525/// Adds a package into database.
7626///
7727/// Package must be built first.
@@ -98,7 +48,7 @@ pub(crate) async fn finish_release(
9848 source_size : u64 ,
9949) -> Result < ( ) > {
10050 debug ! ( "updating release data" ) ;
101- let dependencies = convert_dependencies ( metadata_pkg) ? ;
51+ let dependencies: ReleaseDependencyList = metadata_pkg. dependencies . clone ( ) . into ( ) ;
10252 let rustdoc = get_rustdoc ( metadata_pkg, source_dir) . unwrap_or ( None ) ;
10353 let readme = get_readme ( metadata_pkg, source_dir) . unwrap_or ( None ) ;
10454 let features = get_features ( metadata_pkg) ;
@@ -133,7 +83,7 @@ pub(crate) async fn finish_release(
13383 WHERE id = $1"# ,
13484 release_id. 0 ,
13585 registry_data. release_time,
136- dependencies,
86+ serde_json :: to_value ( & dependencies) ? ,
13787 metadata_pkg. package_name( ) ,
13888 registry_data. yanked,
13989 has_docs,
@@ -432,16 +382,6 @@ pub(crate) async fn initialize_build(
432382 Ok ( build_id)
433383}
434384
435- /// Convert dependencies into our own internal JSON representation
436- fn convert_dependencies ( pkg : & MetadataPackage ) -> Result < serde_json:: Value > {
437- let dependencies: Vec < _ > = pkg
438- . dependencies
439- . iter ( )
440- . map ( |dependency| ReleaseDependency ( dependency. clone ( ) ) )
441- . collect :: < Vec < _ > > ( ) ;
442- Ok ( serde_json:: to_value ( dependencies) ?)
443- }
444-
445385/// Reads features and converts them to Vec<Feature> with default being first
446386fn get_features ( pkg : & MetadataPackage ) -> Vec < Feature > {
447387 let mut features = Vec :: with_capacity ( pkg. features . len ( ) ) ;
0 commit comments