You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #3192 - Turbo87:dep-model, r=pietroalbini
Clean up `dependency` model module
This PR slightly cleans up the `dependency` model module, primarily by moving the `add_dependencies()` function into the corresponding controller. The function is using view-specific classes, which should be avoided in the `models` modules.
r? `@pietroalbini`
returnErr(cargo_err(&format_args!("Dependency `{}` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io.",&*dep.name)));
302
+
}
303
+
}
304
+
305
+
// Match only identical names to ensure the index always references the original crate name
306
+
let krate:Crate = Crate::by_exact_name(&dep.name)
307
+
.first(&*conn)
308
+
.map_err(|_| cargo_err(&format_args!("no known crate named `{}`",&*dep.name)))?;
309
+
if semver::VersionReq::parse(&dep.version_req.0) == semver::VersionReq::parse("*"){
310
+
returnErr(cargo_err(WILDCARD_ERROR_MESSAGE));
311
+
}
312
+
313
+
// If this dependency has an explicit name in `Cargo.toml` that
314
+
// means that the `name` we have listed is actually the package name
315
+
// that we're depending on. The `name` listed in the index is the
316
+
// Cargo.toml-written-name which is what cargo uses for
// if you add a kind here, be sure to update `from_row` below.
50
43
}
51
44
52
-
pubfnadd_dependencies(
53
-
conn:&PgConnection,
54
-
deps:&[EncodableCrateDependency],
55
-
target_version_id:i32,
56
-
) -> AppResult<Vec<git::Dependency>>{
57
-
useself::dependencies::dsl::*;
58
-
use diesel::insert_into;
59
-
60
-
let git_and_new_dependencies = deps
61
-
.iter()
62
-
.map(|dep| {
63
-
ifletSome(registry) = &dep.registry{
64
-
if !registry.is_empty(){
65
-
returnErr(cargo_err(&format_args!("Dependency `{}` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io.",&*dep.name)));
66
-
}
67
-
}
68
-
69
-
// Match only identical names to ensure the index always references the original crate name
70
-
let krate:Crate = Crate::by_exact_name(&dep.name)
71
-
.first(&*conn)
72
-
.map_err(|_| cargo_err(&format_args!("no known crate named `{}`",&*dep.name)))?;
73
-
if semver::VersionReq::parse(&dep.version_req.0) == semver::VersionReq::parse("*"){
74
-
returnErr(cargo_err(WILDCARD_ERROR_MESSAGE));
75
-
}
76
-
77
-
// If this dependency has an explicit name in `Cargo.toml` that
78
-
// means that the `name` we have listed is actually the package name
79
-
// that we're depending on. The `name` listed in the index is the
80
-
// Cargo.toml-written-name which is what cargo uses for
0 commit comments