Skip to content

Commit cb22eb1

Browse files
committed
krate::publish: Simplify add_dependencies() fn
1 parent 0fa285a commit cb22eb1

File tree

1 file changed

+17
-43
lines changed

1 file changed

+17
-43
lines changed

src/controllers/krate/publish.rs

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use std::path::Path;
1414
use crate::controllers::cargo_prelude::*;
1515
use crate::controllers::util::RequestPartsExt;
1616
use crate::models::{
17-
insert_version_owner_action, Category, Crate, DependencyKind, Keyword, NewCrate, NewVersion,
18-
Rights, VersionAction,
17+
insert_version_owner_action, Category, Crate, Keyword, NewCrate, NewVersion, Rights,
18+
VersionAction,
1919
};
2020

2121
use crate::middleware::log_request::RequestLogExt;
@@ -208,9 +208,9 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
208208
// to get here, and max upload sizes are way less than i32 max
209209
content_length as i32,
210210
user.id,
211-
hex_cksum.clone(),
212-
links.clone(),
213-
rust_version.clone(),
211+
hex_cksum,
212+
links,
213+
rust_version,
214214
)?
215215
.save(conn, &verified_email_address)?;
216216

@@ -343,11 +343,11 @@ pub fn add_dependencies(
343343
conn: &mut PgConnection,
344344
deps: &[EncodableCrateDependency],
345345
target_version_id: i32,
346-
) -> AppResult<Vec<cargo_registry_index::Dependency>> {
346+
) -> AppResult<()> {
347347
use self::dependencies::dsl::*;
348348
use diesel::insert_into;
349349

350-
let git_and_new_dependencies = deps
350+
let new_dependencies = deps
351351
.iter()
352352
.map(|dep| {
353353
if let Some(registry) = &dep.registry {
@@ -367,51 +367,25 @@ pub fn add_dependencies(
367367
}
368368
}
369369

370-
// If this dependency has an explicit name in `Cargo.toml` that
371-
// means that the `name` we have listed is actually the package name
372-
// that we're depending on. The `name` listed in the index is the
373-
// Cargo.toml-written-name which is what cargo uses for
374-
// `--extern foo=...`
375-
let (name, package) = match &dep.explicit_name_in_toml {
376-
Some(explicit) => (explicit.to_string(), Some(dep.name.to_string())),
377-
None => (dep.name.to_string(), None),
378-
};
379-
380370
Ok((
381-
cargo_registry_index::Dependency {
382-
name,
383-
req: dep.version_req.to_string(),
384-
features: dep.features.iter().map(|s| s.0.to_string()).collect(),
385-
optional: dep.optional,
386-
default_features: dep.default_features,
387-
target: dep.target.clone(),
388-
kind: dep.kind.or(Some(DependencyKind::Normal)).map(|dk| dk.into()),
389-
package,
390-
},
391-
(
392-
version_id.eq(target_version_id),
393-
crate_id.eq(krate.id),
394-
req.eq(dep.version_req.to_string()),
395-
dep.kind.map(|k| kind.eq(k as i32)),
396-
optional.eq(dep.optional),
397-
default_features.eq(dep.default_features),
398-
features.eq(&dep.features),
399-
target.eq(dep.target.as_deref()),
400-
explicit_name.eq(dep.explicit_name_in_toml.as_deref())
401-
),
371+
version_id.eq(target_version_id),
372+
crate_id.eq(krate.id),
373+
req.eq(dep.version_req.to_string()),
374+
dep.kind.map(|k| kind.eq(k as i32)),
375+
optional.eq(dep.optional),
376+
default_features.eq(dep.default_features),
377+
features.eq(&dep.features),
378+
target.eq(dep.target.as_deref()),
379+
explicit_name.eq(dep.explicit_name_in_toml.as_deref())
402380
))
403381
})
404382
.collect::<Result<Vec<_>, _>>()?;
405383

406-
let (mut git_deps, new_dependencies): (Vec<_>, Vec<_>) =
407-
git_and_new_dependencies.into_iter().unzip();
408-
git_deps.sort();
409-
410384
insert_into(dependencies)
411385
.values(&new_dependencies)
412386
.execute(conn)?;
413387

414-
Ok(git_deps)
388+
Ok(())
415389
}
416390

417391
#[derive(Debug)]

0 commit comments

Comments
 (0)