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 21, 2024
1 parent 4b1fc88 commit 6f5cbe2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
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
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

0 comments on commit 6f5cbe2

Please sign in to comment.