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 Jan 16, 2024
1 parent b454b9f commit cdb15d6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 2 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 @@ -112,6 +112,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
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,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 @@ -934,7 +934,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
1 change: 1 addition & 0 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
let matched = match kind {
QueryKind::Exact => dep.matches(s.as_summary()),
QueryKind::Fuzzy => true,
QueryKind::Normalized => true,
};
// Next filter out all yanked packages. Some yanked packages may
// leak through if they're in a whitelist (aka if they were
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

0 comments on commit cdb15d6

Please sign in to comment.