Skip to content

Commit aef34fe

Browse files
committed
krate::publish: Simplify add_dependencies() fn
1 parent 5a0077f commit aef34fe

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

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

332-
let git_and_new_dependencies = deps
332+
let new_dependencies = deps
333333
.iter()
334334
.map(|dep| {
335335
if let Some(registry) = &dep.registry {
@@ -349,51 +349,25 @@ pub fn add_dependencies(
349349
}
350350
}
351351

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

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

396-
Ok(git_deps)
370+
Ok(())
397371
}
398372

399373
#[instrument(skip_all, fields(%pkg_name))]

0 commit comments

Comments
 (0)