Skip to content

index: Use/Allow alphabetic ordering of features and dependencies #5089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cargo-registry-index/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate serde;
pub mod testing;

use anyhow::{anyhow, Context};
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -101,7 +101,7 @@ pub struct Crate {
pub vers: String,
pub deps: Vec<Dependency>,
pub cksum: String,
pub features: HashMap<String, Vec<String>>,
pub features: BTreeMap<String, Vec<String>>,
/// This field contains features with new, extended syntax. Specifically,
/// namespaced features (`dep:`) and weak dependencies (`pkg?/feat`).
///
Expand All @@ -112,7 +112,7 @@ pub struct Crate {
/// will fail to load due to not being able to parse the new syntax, even
/// with a `Cargo.lock` file.
#[serde(skip_serializing_if = "Option::is_none")]
pub features2: Option<HashMap<String, Vec<String>>>,
pub features2: Option<BTreeMap<String, Vec<String>>>,
pub yanked: Option<bool>,
#[serde(default)]
pub links: Option<String>,
Expand All @@ -139,7 +139,7 @@ pub struct Crate {
pub v: Option<u32>,
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, PartialEq, PartialOrd, Ord, Eq)]
pub struct Dependency {
pub name: String,
pub req: String,
Expand All @@ -152,7 +152,7 @@ pub struct Dependency {
pub package: Option<String>,
}

#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
#[derive(Copy, Clone, Serialize, Deserialize, Debug, PartialEq, PartialOrd, Ord, Eq)]
#[serde(rename_all = "lowercase")]
pub enum DependencyKind {
Normal,
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use flate2::read::GzDecoder;
use hex::ToHex;
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::io::Read;
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult {
.uploader()
.upload_crate(app.http_client(), tarball, &krate, vers)?;

let (features, features2): (HashMap<_, _>, HashMap<_, _>) =
let (features, features2): (BTreeMap<_, _>, BTreeMap<_, _>) =
features.into_iter().partition(|(_k, vals)| {
!vals
.iter()
Expand Down
4 changes: 2 additions & 2 deletions src/downloads_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ mod tests {
use crate::models::{Crate, NewCrate, NewUser, NewVersion, User};
use diesel::PgConnection;
use semver::Version;
use std::collections::HashMap;
use std::collections::BTreeMap;

#[test]
fn test_increment_and_persist_all() {
Expand Down Expand Up @@ -452,7 +452,7 @@ mod tests {
let version = NewVersion::new(
self.krate.id,
&Version::parse(&format!("{}.0.0", self.next_version)).unwrap(),
&HashMap::new(),
&BTreeMap::new(),
None,
None,
0,
Expand Down
4 changes: 2 additions & 2 deletions src/models/version.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::BTreeMap;

use chrono::NaiveDateTime;
use diesel::prelude::*;
Expand Down Expand Up @@ -127,7 +127,7 @@ impl NewVersion {
pub fn new(
crate_id: i32,
num: &semver::Version,
features: &HashMap<String, Vec<String>>,
features: &BTreeMap<String, Vec<String>>,
license: Option<String>,
license_file: Option<&str>,
crate_size: i32,
Expand Down
6 changes: 3 additions & 3 deletions src/tests/builders/publish.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cargo_registry::views::krate_publish as u;
use std::{collections::HashMap, io::Read};
use std::{collections::BTreeMap, collections::HashMap, io::Read};

use flate2::{write::GzEncoder, Compression};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct PublishBuilder {
readme: Option<String>,
tarball: Vec<u8>,
version: semver::Version,
features: HashMap<u::EncodableFeatureName, Vec<u::EncodableFeature>>,
features: BTreeMap<u::EncodableFeatureName, Vec<u::EncodableFeature>>,
}

impl PublishBuilder {
Expand All @@ -56,7 +56,7 @@ impl PublishBuilder {
readme: None,
tarball: EMPTY_TARBALL_BYTES.to_vec(),
version: semver::Version::parse("1.0.0").unwrap(),
features: HashMap::new(),
features: BTreeMap::new(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests/builders/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cargo_registry::{
schema::{dependencies, versions},
util::errors::AppResult,
};
use std::collections::HashMap;
use std::collections::BTreeMap;

use chrono::NaiveDateTime;
use diesel::prelude::*;
Expand All @@ -12,7 +12,7 @@ use diesel::prelude::*;
pub struct VersionBuilder<'a> {
created_at: Option<NaiveDateTime>,
dependencies: Vec<(i32, Option<&'static str>)>,
features: HashMap<String, Vec<String>>,
features: BTreeMap<String, Vec<String>>,
license: Option<&'a str>,
license_file: Option<&'a str>,
num: semver::Version,
Expand All @@ -36,7 +36,7 @@ impl<'a> VersionBuilder<'a> {
VersionBuilder {
created_at: None,
dependencies: Vec::new(),
features: HashMap::new(),
features: BTreeMap::new(),
license: None,
license_file: None,
num,
Expand Down
6 changes: 3 additions & 3 deletions src/tests/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use diesel::{delete, update, ExpressionMethods, QueryDsl, RunQueryDsl};
use flate2::write::GzEncoder;
use flate2::Compression;
use http::StatusCode;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::io::Read;
use std::iter::FromIterator;
use std::time::Duration;
Expand Down Expand Up @@ -953,9 +953,9 @@ fn features_version_2() {
assert_eq!(crates[0].name, "foo");
assert_eq!(crates[0].deps.len(), 1);
assert_eq!(crates[0].v, Some(2));
let features = HashMap::from_iter([("old_feat".to_string(), vec![])]);
let features = BTreeMap::from_iter([("old_feat".to_string(), vec![])]);
assert_eq!(crates[0].features, features);
let features2 = HashMap::from_iter([(
let features2 = BTreeMap::from_iter([(
"new_feat".to_string(),
vec!["dep:bar".to_string(), "bar?/feat".to_string()],
)]);
Expand Down
6 changes: 3 additions & 3 deletions src/views/krate_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! and manages the serialising and deserialising of this information
//! to and from structs. The serlializing is only utilised in
//! integration tests.
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};

Expand All @@ -17,7 +17,7 @@ pub struct EncodableCrateUpload {
pub name: EncodableCrateName,
pub vers: EncodableCrateVersion,
pub deps: Vec<EncodableCrateDependency>,
pub features: HashMap<EncodableFeatureName, Vec<EncodableFeature>>,
pub features: BTreeMap<EncodableFeatureName, Vec<EncodableFeature>>,
pub description: Option<String>,
pub homepage: Option<String>,
pub documentation: Option<String>,
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct EncodableCategoryList(pub Vec<EncodableCategory>);
pub struct EncodableCategory(pub String);
#[derive(Serialize, Debug, Deref)]
pub struct EncodableFeature(pub String);
#[derive(PartialEq, Eq, Hash, Serialize, Debug, Deref)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Debug, Deref)]
pub struct EncodableFeatureName(pub String);

#[derive(Serialize, Deserialize, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/worker/update_downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod test {
use super::*;
use crate::email::Emails;
use crate::models::{Crate, NewCrate, NewUser, NewVersion, User, Version};
use std::collections::HashMap;
use std::collections::BTreeMap;

fn user(conn: &PgConnection) -> User {
NewUser::new(2, "login", None, None, "access_token")
Expand All @@ -103,7 +103,7 @@ mod test {
let version = NewVersion::new(
krate.id,
&semver::Version::parse("1.0.0").unwrap(),
&HashMap::new(),
&BTreeMap::new(),
None,
None,
0,
Expand Down