Skip to content

Commit 04db8a7

Browse files
Merge #1537
1537: Bump semver r=jtgeibel a=sgrif The amount of manual serialization/deserialization of semver stuff is really starting to get in the way of refactoring. Semver supports both Serde and Diesel on master (only serde in the released version, hence the git dependency). Conduit still expects an older version though. That project is unmaintained and I've been having trouble getting added as an owner to publish a new version (Alex is in Europe right now, not worth bothering him) so we've got a little hacky workaround in the meantime. Co-authored-by: Sean Griffin <[email protected]>
2 parents 41bf7a4 + d817947 commit 04db8a7

File tree

7 files changed

+38
-88
lines changed

7 files changed

+38
-88
lines changed

Cargo.lock

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ rustdoc-args = [
2828

2929
[dependencies]
3030
cargo-registry-s3 = { path = "src/s3", version = "0.2.0" }
31+
old_semver = { path = "src/old_semver", version = "0.1.0" }
3132
rand = "0.3"
3233
git2 = "0.6.4"
3334
flate2 = "1.0"
34-
semver = "0.5"
35+
semver = { version = "0.9", git = "https://github.com/steveklabnik/semver.git", features = ["diesel", "serde"] }
3536
url = "1.2.1"
3637
tar = "0.4.13"
3738
base64 = "0.9"

src/models/dependency.rs

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use diesel::deserialize::QueryableByName;
2-
use diesel::pg::Pg;
31
use diesel::prelude::*;
4-
use diesel::row::NamedRow;
52
use semver;
63

74
use git;
@@ -11,7 +8,7 @@ use models::{Crate, Version};
118
use schema::*;
129
use views::{EncodableCrateDependency, EncodableDependency};
1310

14-
#[derive(Identifiable, Associations, Debug)]
11+
#[derive(Identifiable, Associations, Debug, Queryable, QueryableByName)]
1512
#[belongs_to(Version)]
1613
#[belongs_to(Crate)]
1714
#[table_name = "dependencies"]
@@ -141,6 +138,7 @@ pub fn add_dependencies(
141138
}
142139

143140
use diesel::deserialize::{self, FromSql};
141+
use diesel::pg::Pg;
144142
use diesel::sql_types::Integer;
145143

146144
impl FromSql<Integer, Pg> for DependencyKind {
@@ -153,51 +151,3 @@ impl FromSql<Integer, Pg> for DependencyKind {
153151
}
154152
}
155153
}
156-
157-
impl Queryable<dependencies::SqlType, Pg> for Dependency {
158-
type Row = (
159-
i32,
160-
i32,
161-
i32,
162-
String,
163-
bool,
164-
bool,
165-
Vec<String>,
166-
Option<String>,
167-
DependencyKind,
168-
);
169-
170-
fn build(row: Self::Row) -> Self {
171-
Dependency {
172-
id: row.0,
173-
version_id: row.1,
174-
crate_id: row.2,
175-
req: semver::VersionReq::parse(&row.3).unwrap(),
176-
optional: row.4,
177-
default_features: row.5,
178-
features: row.6,
179-
target: row.7,
180-
kind: row.8,
181-
}
182-
}
183-
}
184-
185-
impl QueryableByName<Pg> for Dependency {
186-
fn build<R: NamedRow<Pg>>(row: &R) -> deserialize::Result<Self> {
187-
use diesel::dsl::SqlTypeOf;
188-
use schema::dependencies::*;
189-
190-
let req_str = row.get::<SqlTypeOf<req>, String>("req")?;
191-
Ok(Dependency {
192-
id: row.get::<SqlTypeOf<id>, _>("id")?,
193-
version_id: row.get::<SqlTypeOf<version_id>, _>("version_id")?,
194-
crate_id: row.get::<SqlTypeOf<crate_id>, _>("crate_id")?,
195-
req: semver::VersionReq::parse(&req_str)?,
196-
optional: row.get::<SqlTypeOf<optional>, _>("optional")?,
197-
default_features: row.get::<SqlTypeOf<default_features>, _>("default_features")?,
198-
features: row.get::<SqlTypeOf<features>, _>("features")?,
199-
target: row.get::<SqlTypeOf<target>, _>("target")?,
200-
kind: row.get::<SqlTypeOf<kind>, _>("kind")?,
201-
})
202-
}
203-
}

src/models/version.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::collections::HashMap;
22

33
use chrono::NaiveDateTime;
44
use diesel;
5-
use diesel::pg::Pg;
65
use diesel::prelude::*;
76
use semver;
87
use serde_json;
@@ -15,7 +14,7 @@ use schema::*;
1514
use views::{EncodableVersion, EncodableVersionLinks};
1615

1716
// Queryable has a custom implementation below
18-
#[derive(Clone, Identifiable, Associations, Debug)]
17+
#[derive(Clone, Identifiable, Associations, Debug, Queryable)]
1918
#[belongs_to(Crate)]
2019
pub struct Version {
2120
pub id: i32,
@@ -193,34 +192,3 @@ impl NewVersion {
193192
Ok(())
194193
}
195194
}
196-
197-
impl Queryable<versions::SqlType, Pg> for Version {
198-
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
199-
type Row = (
200-
i32,
201-
i32,
202-
String,
203-
NaiveDateTime,
204-
NaiveDateTime,
205-
i32,
206-
serde_json::Value,
207-
bool,
208-
Option<String>,
209-
Option<i32>,
210-
);
211-
212-
fn build(row: Self::Row) -> Self {
213-
Version {
214-
id: row.0,
215-
crate_id: row.1,
216-
num: semver::Version::parse(&row.2).unwrap(),
217-
updated_at: row.3,
218-
created_at: row.4,
219-
downloads: row.5,
220-
features: row.6,
221-
yanked: row.7,
222-
license: row.8,
223-
crate_size: row.9,
224-
}
225-
}
226-
}

src/old_semver/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "old_semver"
3+
version = "0.1.0"
4+
authors = ["Sean Griffin <[email protected]>"]
5+
6+
[dependencies]
7+
semver = "0.5.0"

src/old_semver/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// We need semver 0.5.0 for conduit, but we want to use newer versions.
2+
/// This is a silly workaround.
3+
pub extern crate semver;

src/util/request_proxy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
extern crate old_semver;
2+
13
use std::io::Read;
24
use std::net::SocketAddr;
35

6+
use self::old_semver::semver;
47
use conduit;
58
use conduit::Request;
6-
use semver;
79

810
// Can't derive Debug because of Request.
911
#[allow(missing_debug_implementations)]

0 commit comments

Comments
 (0)