Skip to content

Commit 6c771c6

Browse files
committed
krate::publish: Simplify add_dependencies() fn
1 parent 6bded67 commit 6c771c6

File tree

1 file changed

+16
-42
lines changed

1 file changed

+16
-42
lines changed

src/controllers/krate/publish.rs

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

2020
use crate::middleware::log_request::RequestLogExt;
@@ -198,8 +198,8 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
198198
// to get here, and max upload sizes are way less than i32 max
199199
content_length as i32,
200200
user.id,
201-
hex_cksum.clone(),
202-
links.clone(),
201+
hex_cksum,
202+
links,
203203
)?
204204
.save(conn, &verified_email_address)?;
205205

@@ -324,11 +324,11 @@ pub fn add_dependencies(
324324
conn: &mut PgConnection,
325325
deps: &[EncodableCrateDependency],
326326
target_version_id: i32,
327-
) -> AppResult<Vec<cargo_registry_index::Dependency>> {
327+
) -> AppResult<()> {
328328
use self::dependencies::dsl::*;
329329
use diesel::insert_into;
330330

331-
let git_and_new_dependencies = deps
331+
let new_dependencies = deps
332332
.iter()
333333
.map(|dep| {
334334
if let Some(registry) = &dep.registry {
@@ -348,51 +348,25 @@ pub fn add_dependencies(
348348
}
349349
}
350350

351-
// If this dependency has an explicit name in `Cargo.toml` that
352-
// means that the `name` we have listed is actually the package name
353-
// that we're depending on. The `name` listed in the index is the
354-
// Cargo.toml-written-name which is what cargo uses for
355-
// `--extern foo=...`
356-
let (name, package) = match &dep.explicit_name_in_toml {
357-
Some(explicit) => (explicit.to_string(), Some(dep.name.to_string())),
358-
None => (dep.name.to_string(), None),
359-
};
360-
361351
Ok((
362-
cargo_registry_index::Dependency {
363-
name,
364-
req: dep.version_req.to_string(),
365-
features: dep.features.iter().map(|s| s.0.to_string()).collect(),
366-
optional: dep.optional,
367-
default_features: dep.default_features,
368-
target: dep.target.clone(),
369-
kind: dep.kind.or(Some(DependencyKind::Normal)).map(|dk| dk.into()),
370-
package,
371-
},
372-
(
373-
version_id.eq(target_version_id),
374-
crate_id.eq(krate.id),
375-
req.eq(dep.version_req.to_string()),
376-
dep.kind.map(|k| kind.eq(k as i32)),
377-
optional.eq(dep.optional),
378-
default_features.eq(dep.default_features),
379-
features.eq(&dep.features),
380-
target.eq(dep.target.as_deref()),
381-
explicit_name.eq(dep.explicit_name_in_toml.as_deref())
382-
),
352+
version_id.eq(target_version_id),
353+
crate_id.eq(krate.id),
354+
req.eq(dep.version_req.to_string()),
355+
dep.kind.map(|k| kind.eq(k as i32)),
356+
optional.eq(dep.optional),
357+
default_features.eq(dep.default_features),
358+
features.eq(&dep.features),
359+
target.eq(dep.target.as_deref()),
360+
explicit_name.eq(dep.explicit_name_in_toml.as_deref())
383361
))
384362
})
385363
.collect::<Result<Vec<_>, _>>()?;
386364

387-
let (mut git_deps, new_dependencies): (Vec<_>, Vec<_>) =
388-
git_and_new_dependencies.into_iter().unzip();
389-
git_deps.sort();
390-
391365
insert_into(dependencies)
392366
.values(&new_dependencies)
393367
.execute(conn)?;
394368

395-
Ok(git_deps)
369+
Ok(())
396370
}
397371

398372
fn verify_tarball(

0 commit comments

Comments
 (0)