Skip to content

Commit 4720824

Browse files
committed
helpers to check if precise is set
1 parent c269439 commit 4720824

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/cargo/core/registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'cfg> PackageRegistry<'cfg> {
161161

162162
// If the previous source was not a precise source, then we can be
163163
// sure that it's already been updated if we've already loaded it.
164-
Some((previous, _)) if previous.precise().is_none() => {
164+
Some((previous, _)) if !previous.has_precise() => {
165165
debug!("load/precise {}", namespace);
166166
return Ok(());
167167
}
@@ -471,9 +471,9 @@ impl<'cfg> PackageRegistry<'cfg> {
471471
//
472472
// If we have a precise version, then we'll update lazily during the
473473
// querying phase. Note that precise in this case is only
474-
// `Some("locked")` as other `Some` values indicate a `cargo update
474+
// `"locked"` as other values indicate a `cargo update
475475
// --precise` request
476-
if source_id.precise() != Some("locked") {
476+
if !source_id.has_locked_precise() {
477477
self.sources.get_mut(source_id).unwrap().invalidate_cache();
478478
} else {
479479
debug!("skipping update due to locked registry");

src/cargo/core/source_id.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl SourceId {
332332
pub fn display_registry_name(self) -> String {
333333
if let Some(key) = self.inner.registry_key.as_ref().map(|k| k.key()) {
334334
key.into()
335-
} else if self.precise().is_some() {
335+
} else if self.has_precise() {
336336
// We remove `precise` here to retrieve an permissive version of
337337
// `SourceIdInner`, which may contain the registry name.
338338
self.with_precise(None).display_registry_name()
@@ -449,6 +449,16 @@ impl SourceId {
449449
self.inner.precise.as_deref()
450450
}
451451

452+
/// Check if the precise data field has bean set
453+
pub fn has_precise(self) -> bool {
454+
self.inner.precise.is_some()
455+
}
456+
457+
/// Check if the precise data field has bean set to "Locked"
458+
pub fn has_locked_precise(self) -> bool {
459+
self.inner.precise.as_deref() == Some("locked")
460+
}
461+
452462
/// Check if the precise data field stores information for this `name`
453463
/// from a call to [SourceId::with_precise_registry_version].
454464
///

src/cargo/sources/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ a lock file compatible with `{orig}` cannot be generated in this situation
199199
);
200200
}
201201

202-
if old_src.requires_precise() && id.precise().is_none() {
202+
if old_src.requires_precise() && !id.has_precise() {
203203
bail!(
204204
"\
205205
the source {orig} requires a lock file to be present first before it can be

src/cargo/sources/registry/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
716716
// theory the registry is known to contain this version. If, however, we
717717
// come back with no summaries, then our registry may need to be
718718
// updated, so we fall back to performing a lazy update.
719-
if kind == QueryKind::Exact && dep.source_id().precise().is_some() && !self.ops.is_updated()
720-
{
719+
if kind == QueryKind::Exact && dep.source_id().has_precise() && !self.ops.is_updated() {
721720
debug!("attempting query without update");
722721
let mut called = false;
723722
ready!(self.index.query_inner(

0 commit comments

Comments
 (0)