Skip to content

Commit

Permalink
fix(cargo-update): once warn once for --precise <yanked>
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jan 29, 2024
1 parent 6c10832 commit 17cae8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
23 changes: 16 additions & 7 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ pub struct RegistrySource<'cfg> {
/// Otherwise, the resolver would think that those entries no longer
/// exist, and it would trigger updates to unrelated packages.
yanked_whitelist: HashSet<PackageId>,
/// Yanked versions that have already been selected during queries.
///
/// As of this writing, this is for not emitting the `--precise <yanked>`
/// warning twice, with the assumption of (`dep.package_name()` + `--precise`
/// version) being sufficient to uniquely identify the same query result.
selected_precise_yanked: HashSet<(InternedString, semver::Version)>,
}

/// The [`config.json`] file stored in the index.
Expand Down Expand Up @@ -531,6 +537,7 @@ impl<'cfg> RegistrySource<'cfg> {
index: index::RegistryIndex::new(source_id, ops.index_path(), config),
yanked_whitelist: yanked_whitelist.clone(),
ops,
selected_precise_yanked: HashSet::new(),
}
}

Expand Down Expand Up @@ -812,13 +819,15 @@ impl<'cfg> Source for RegistrySource<'cfg> {
let version = req
.precise_version()
.expect("--precise <yanked-version> in use");
let source = self.source_id();
let mut shell = self.config.shell();
shell.warn(format_args!(
"yanked package `{name}@{version}` is selected by the `--precise` flag from {source}",
))?;
shell.note("it is not recommended to depend on a yanked version")?;
shell.note("if possible, try other SemVer-compatbile versions")?;
if self.selected_precise_yanked.insert((name, version.clone())) {
let source = self.source_id();
let mut shell = self.config.shell();
shell.warn(format_args!(
"yanked package `{name}@{version}` is selected by the `--precise` flag from {source}",
))?;
shell.note("it is not recommended to depend on a yanked version")?;
shell.note("if possible, try other SemVer-compatible versions")?;
}
}
if called {
return Poll::Ready(Ok(()));
Expand Down
7 changes: 2 additions & 5 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ Caused by:
[UPDATING] `dummy-registry` index
[WARNING] yanked package `bar@0.1.1` is selected by the `--precise` flag from registry `dummy-registry`
[NOTE] it is not recommended to depend on a yanked version
[NOTE] if possible, try other SemVer-compatbile versions
[NOTE] if possible, try other SemVer-compatible versions
[UPDATING] bar v0.1.0 -> v0.1.1
",
)
Expand Down Expand Up @@ -1465,10 +1465,7 @@ fn precise_yanked_multiple_presence() {
[UPDATING] `dummy-registry` index
[WARNING] yanked package `bar@0.1.1` is selected by the `--precise` flag from registry `dummy-registry`
[NOTE] it is not recommended to depend on a yanked version
[NOTE] if possible, try other SemVer-compatbile versions
[WARNING] yanked package `bar@0.1.1` is selected by the `--precise` flag from registry `dummy-registry`
[NOTE] it is not recommended to depend on a yanked version
[NOTE] if possible, try other SemVer-compatbile versions
[NOTE] if possible, try other SemVer-compatible versions
[UPDATING] bar v0.1.0 -> v0.1.1
",
)
Expand Down

0 comments on commit 17cae8e

Please sign in to comment.