Skip to content

Commit

Permalink
Merge #1537
Browse files Browse the repository at this point in the history
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 <sean@seantheprogrammer.com>
  • Loading branch information
bors-voyager[bot] and sgrif committed Oct 24, 2018
2 parents 41bf7a4 + d817947 commit 04db8a7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 88 deletions.
21 changes: 20 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -28,10 +28,11 @@ rustdoc-args = [

[dependencies]
cargo-registry-s3 = { path = "src/s3", version = "0.2.0" }
old_semver = { path = "src/old_semver", version = "0.1.0" }
rand = "0.3"
git2 = "0.6.4"
flate2 = "1.0"
semver = "0.5"
semver = { version = "0.9", git = "https://github.com/steveklabnik/semver.git", features = ["diesel", "serde"] }
url = "1.2.1"
tar = "0.4.13"
base64 = "0.9"
Expand Down
54 changes: 2 additions & 52 deletions src/models/dependency.rs
@@ -1,7 +1,4 @@
use diesel::deserialize::QueryableByName;
use diesel::pg::Pg;
use diesel::prelude::*;
use diesel::row::NamedRow;
use semver;

use git;
Expand All @@ -11,7 +8,7 @@ use models::{Crate, Version};
use schema::*;
use views::{EncodableCrateDependency, EncodableDependency};

#[derive(Identifiable, Associations, Debug)]
#[derive(Identifiable, Associations, Debug, Queryable, QueryableByName)]
#[belongs_to(Version)]
#[belongs_to(Crate)]
#[table_name = "dependencies"]
Expand Down Expand Up @@ -141,6 +138,7 @@ pub fn add_dependencies(
}

use diesel::deserialize::{self, FromSql};
use diesel::pg::Pg;
use diesel::sql_types::Integer;

impl FromSql<Integer, Pg> for DependencyKind {
Expand All @@ -153,51 +151,3 @@ impl FromSql<Integer, Pg> for DependencyKind {
}
}
}

impl Queryable<dependencies::SqlType, Pg> for Dependency {
type Row = (
i32,
i32,
i32,
String,
bool,
bool,
Vec<String>,
Option<String>,
DependencyKind,
);

fn build(row: Self::Row) -> Self {
Dependency {
id: row.0,
version_id: row.1,
crate_id: row.2,
req: semver::VersionReq::parse(&row.3).unwrap(),
optional: row.4,
default_features: row.5,
features: row.6,
target: row.7,
kind: row.8,
}
}
}

impl QueryableByName<Pg> for Dependency {
fn build<R: NamedRow<Pg>>(row: &R) -> deserialize::Result<Self> {
use diesel::dsl::SqlTypeOf;
use schema::dependencies::*;

let req_str = row.get::<SqlTypeOf<req>, String>("req")?;
Ok(Dependency {
id: row.get::<SqlTypeOf<id>, _>("id")?,
version_id: row.get::<SqlTypeOf<version_id>, _>("version_id")?,
crate_id: row.get::<SqlTypeOf<crate_id>, _>("crate_id")?,
req: semver::VersionReq::parse(&req_str)?,
optional: row.get::<SqlTypeOf<optional>, _>("optional")?,
default_features: row.get::<SqlTypeOf<default_features>, _>("default_features")?,
features: row.get::<SqlTypeOf<features>, _>("features")?,
target: row.get::<SqlTypeOf<target>, _>("target")?,
kind: row.get::<SqlTypeOf<kind>, _>("kind")?,
})
}
}
34 changes: 1 addition & 33 deletions src/models/version.rs
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;

use chrono::NaiveDateTime;
use diesel;
use diesel::pg::Pg;
use diesel::prelude::*;
use semver;
use serde_json;
Expand All @@ -15,7 +14,7 @@ use schema::*;
use views::{EncodableVersion, EncodableVersionLinks};

// Queryable has a custom implementation below
#[derive(Clone, Identifiable, Associations, Debug)]
#[derive(Clone, Identifiable, Associations, Debug, Queryable)]
#[belongs_to(Crate)]
pub struct Version {
pub id: i32,
Expand Down Expand Up @@ -193,34 +192,3 @@ impl NewVersion {
Ok(())
}
}

impl Queryable<versions::SqlType, Pg> for Version {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
type Row = (
i32,
i32,
String,
NaiveDateTime,
NaiveDateTime,
i32,
serde_json::Value,
bool,
Option<String>,
Option<i32>,
);

fn build(row: Self::Row) -> Self {
Version {
id: row.0,
crate_id: row.1,
num: semver::Version::parse(&row.2).unwrap(),
updated_at: row.3,
created_at: row.4,
downloads: row.5,
features: row.6,
yanked: row.7,
license: row.8,
crate_size: row.9,
}
}
}
7 changes: 7 additions & 0 deletions src/old_semver/Cargo.toml
@@ -0,0 +1,7 @@
[package]
name = "old_semver"
version = "0.1.0"
authors = ["Sean Griffin <sean@seantheprogrammer.com>"]

[dependencies]
semver = "0.5.0"
3 changes: 3 additions & 0 deletions src/old_semver/src/lib.rs
@@ -0,0 +1,3 @@
/// We need semver 0.5.0 for conduit, but we want to use newer versions.
/// This is a silly workaround.
pub extern crate semver;
4 changes: 3 additions & 1 deletion src/util/request_proxy.rs
@@ -1,9 +1,11 @@
extern crate old_semver;

use std::io::Read;
use std::net::SocketAddr;

use self::old_semver::semver;
use conduit;
use conduit::Request;
use semver;

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

0 comments on commit 04db8a7

Please sign in to comment.