Skip to content

Commit f12f025

Browse files
committed
Remove the update method on registry functions. Instead of explicitly
updating, registries now update as needed. To force a registry to ensure the latest copy of crate metadata is available, a new method called `invalidate_cache` is added. This method will cause the registry to update the next time `block_until_ready` is called.
1 parent 82093ad commit f12f025

18 files changed

+506
-423
lines changed

src/cargo/core/compiler/future_incompat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
281281
})
282282
.collect();
283283

284-
// Query the sources for available versions, mapping `package_ids` into `summaries`.
284+
// Query the sources for new versions, mapping `package_ids` into `summaries`.
285285
let mut summaries = Vec::new();
286286
while !package_ids.is_empty() {
287287
package_ids.retain(|&pkg_id| {

src/cargo/core/registry.rs

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::core::{Dependency, PackageId, Source, SourceId, SourceMap, Summary};
66
use crate::sources::config::SourceConfigMap;
77
use crate::util::errors::CargoResult;
88
use crate::util::interning::InternedString;
9-
use crate::util::{profile, CanonicalUrl, Config};
9+
use crate::util::{CanonicalUrl, Config};
1010
use anyhow::{bail, Context as _};
1111
use log::{debug, trace};
1212
use url::Url;
@@ -180,6 +180,7 @@ impl<'cfg> PackageRegistry<'cfg> {
180180
}
181181

182182
self.load(namespace, kind)?;
183+
self.block_until_ready()?;
183184
Ok(())
184185
}
185186

@@ -446,38 +447,46 @@ impl<'cfg> PackageRegistry<'cfg> {
446447
}
447448

448449
fn load(&mut self, source_id: SourceId, kind: Kind) -> CargoResult<()> {
449-
(|| {
450-
debug!("loading source {}", source_id);
451-
let source = self.source_config.load(source_id, &self.yanked_whitelist)?;
452-
assert_eq!(source.source_id(), source_id);
453-
454-
if kind == Kind::Override {
455-
self.overrides.push(source_id);
456-
}
457-
self.add_source(source, kind);
450+
debug!("loading source {}", source_id);
451+
let source = self
452+
.source_config
453+
.load(source_id, &self.yanked_whitelist)
454+
.with_context(|| format!("Unable to update {}", source_id))?;
455+
assert_eq!(source.source_id(), source_id);
456+
457+
if kind == Kind::Override {
458+
self.overrides.push(source_id);
459+
}
460+
self.add_source(source, kind);
458461

459-
// Ensure the source has fetched all necessary remote data.
460-
let _p = profile::start(format!("updating: {}", source_id));
461-
self.sources.get_mut(source_id).unwrap().update()
462-
})()
463-
.with_context(|| format!("Unable to update {}", source_id))?;
462+
// If we have an imprecise version then we don't know what we're going
463+
// to look for, so we always attempt to perform an update here.
464+
//
465+
// If we have a precise version, then we'll update lazily during the
466+
// querying phase. Note that precise in this case is only
467+
// `Some("locked")` as other `Some` values indicate a `cargo update
468+
// --precise` request
469+
if source_id.precise() != Some("locked") {
470+
self.sources.get_mut(source_id).unwrap().invalidate_cache();
471+
} else {
472+
debug!("skipping update due to locked registry");
473+
}
464474
Ok(())
465475
}
466476

467-
fn query_overrides(&mut self, dep: &Dependency) -> CargoResult<Option<Summary>> {
477+
fn query_overrides(&mut self, dep: &Dependency) -> Poll<CargoResult<Option<Summary>>> {
468478
for &s in self.overrides.iter() {
469479
let src = self.sources.get_mut(s).unwrap();
470480
let dep = Dependency::new_override(dep.package_name(), s);
471-
match src.query_vec(&dep)? {
472-
Poll::Ready(mut results) => {
473-
if !results.is_empty() {
474-
return Ok(Some(results.remove(0)));
475-
}
476-
}
477-
Poll::Pending => panic!("overrides have to be on path deps, how did we get here?"),
481+
let mut results = match src.query_vec(&dep) {
482+
Poll::Ready(results) => results?,
483+
Poll::Pending => return Poll::Pending,
484+
};
485+
if !results.is_empty() {
486+
return Poll::Ready(Ok(Some(results.remove(0))));
478487
}
479488
}
480-
Ok(None)
489+
Poll::Ready(Ok(None))
481490
}
482491

483492
/// This function is used to transform a summary to another locked summary
@@ -567,7 +576,10 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
567576
assert!(self.patches_locked);
568577
let (override_summary, n, to_warn) = {
569578
// Look for an override and get ready to query the real source.
570-
let override_summary = self.query_overrides(dep)?;
579+
let override_summary = match self.query_overrides(dep) {
580+
Poll::Ready(override_summary) => override_summary?,
581+
Poll::Pending => return Poll::Pending,
582+
};
571583

572584
// Next up on our list of candidates is to check the `[patch]`
573585
// section of the manifest. Here we look through all patches
@@ -715,8 +727,10 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
715727
}
716728

717729
fn block_until_ready(&mut self) -> CargoResult<()> {
718-
for (_, source) in self.sources.sources_mut() {
719-
source.block_until_ready()?;
730+
for (source_id, source) in self.sources.sources_mut() {
731+
source
732+
.block_until_ready()
733+
.with_context(|| format!("Unable to update {}", source_id))?;
720734
}
721735
Ok(())
722736
}

src/cargo/core/resolver/dep_cache.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,13 @@ impl<'a> RegistryQueryer<'a> {
150150
.iter()
151151
.map(|s| format!(" * {}", s.package_id()))
152152
.collect::<Vec<_>>();
153-
return Err(anyhow::anyhow!(
153+
return Poll::Ready(Err(anyhow::anyhow!(
154154
"the replacement specification `{}` matched \
155155
multiple packages:\n * {}\n{}",
156156
spec,
157157
s.package_id(),
158158
bullets.join("\n")
159-
))
160-
.into();
159+
)));
161160
}
162161

163162
// The dependency should be hard-coded to have the same name and an
@@ -176,14 +175,13 @@ impl<'a> RegistryQueryer<'a> {
176175

177176
// Make sure no duplicates
178177
if let Some(&(ref spec, _)) = potential_matches.next() {
179-
return Err(anyhow::anyhow!(
178+
return Poll::Ready(Err(anyhow::anyhow!(
180179
"overlapping replacement specifications found:\n\n \
181180
* {}\n * {}\n\nboth specifications match: {}",
182181
matched_spec,
183182
spec,
184183
summary.package_id()
185-
))
186-
.into();
184+
)));
187185
}
188186

189187
for dep in summary.dependencies() {
@@ -245,7 +243,9 @@ impl<'a> RegistryQueryer<'a> {
245243
Poll::Ready(Ok(candidates)) => Some(Ok((dep, candidates, features))),
246244
Poll::Pending => {
247245
all_ready = false;
248-
None // we can ignore Pending deps, resolve will be repeatedly called until there are none to ignore
246+
// we can ignore Pending deps, resolve will be repeatedly called
247+
// until there are none to ignore
248+
None
249249
}
250250
Poll::Ready(Err(e)) => Some(Err(e).with_context(|| {
251251
format!(

0 commit comments

Comments
 (0)