Skip to content

Commit

Permalink
Added QueryKind::Normalized, and used it in cargo-add
Browse files Browse the repository at this point in the history
  • Loading branch information
LuuuXXX committed Feb 22, 2024
1 parent 7dc7b1b commit 3b36aa8
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub fn resolve_with_config_raw(
let matched = match kind {
QueryKind::Exact => dep.matches(summary),
QueryKind::Fuzzy => true,
QueryKind::Normalized => true,
};
if matched {
self.used.insert(summary.package_id());
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ fn get_latest_dependency(
}
MaybeWorkspace::Other(query) => {
let possibilities = loop {
match registry.query_vec(&query, QueryKind::Fuzzy) {
match registry.query_vec(&query, QueryKind::Normalized) {
std::task::Poll::Ready(res) => {
break res?;
}
Expand Down Expand Up @@ -711,7 +711,7 @@ fn select_package(
MaybeWorkspace::Other(query) => {
let possibilities = loop {
// Exact to avoid returning all for path/git
match registry.query_vec(&query, QueryKind::Exact) {
match registry.query_vec(&query, QueryKind::Normalized) {
std::task::Poll::Ready(res) => {
break res?;
}
Expand Down Expand Up @@ -938,7 +938,7 @@ fn populate_available_features(
}

let possibilities = loop {
match registry.query_vec(&query, QueryKind::Exact) {
match registry.query_vec(&query, QueryKind::Normalized) {
std::task::Poll::Ready(res) => {
break res?;
}
Expand Down
1 change: 1 addition & 0 deletions src/cargo/sources/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {
let matches = packages.filter(|pkg| match kind {
QueryKind::Exact => dep.matches(pkg.summary()),
QueryKind::Fuzzy => true,
QueryKind::Normalized => dep.matches(pkg.summary()),
});
for summary in matches.map(|pkg| pkg.summary().clone()) {
f(IndexSummary::Candidate(summary));
Expand Down
1 change: 1 addition & 0 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ impl<'cfg> Source for PathSource<'cfg> {
let matched = match kind {
QueryKind::Exact => dep.matches(s),
QueryKind::Fuzzy => true,
QueryKind::Normalized => dep.matches(s),
};
if matched {
f(IndexSummary::Candidate(s.clone()))
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
let matched = match kind {
QueryKind::Exact => dep.matches(s.as_summary()),
QueryKind::Fuzzy => true,
QueryKind::Normalized => true,
};
if !matched {
return;
Expand Down Expand Up @@ -831,7 +832,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
return Poll::Ready(Ok(()));
}
let mut any_pending = false;
if kind == QueryKind::Fuzzy {
if kind == QueryKind::Fuzzy || kind == QueryKind::Normalized {
// Attempt to handle misspellings by searching for a chain of related
// names to the original name. The resolver will later
// reject any candidates that have the wrong name, and with this it'll
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/sources/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ pub enum QueryKind {
/// whereas an `Registry` source may return dependencies that have the same
/// canonicalization.
Fuzzy,
/// Match a denpendency in all ways and will normalize the package name.
/// Each source defines what normalizing means.
Normalized,
}

/// A download status that represents if a [`Package`] has already been
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn case() {
.arg_line("cbindgen")
.current_dir(cwd)
.assert()
.success()
.failure()
.stdout_matches(file!["stdout.log"])
.stderr_matches(file!["stderr.log"]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"

[dependencies]
aa = "0.0.0"
version = "0.0.0"
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
warning: translating `cbindgen` to `aa`
Adding aa v0.0.0 to dependencies
error: the crate `cbindgen` could not be found in registry index.

0 comments on commit 3b36aa8

Please sign in to comment.