Skip to content

Commit e85a330

Browse files
committed
move yank handling up
1 parent a2bd2b9 commit e85a330

File tree

2 files changed

+27
-55
lines changed

2 files changed

+27
-55
lines changed

src/cargo/sources/registry/index.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ use serde::Deserialize;
100100
use std::borrow::Cow;
101101
use std::cmp::Ordering;
102102
use std::collections::BTreeMap;
103-
use std::collections::{HashMap, HashSet};
103+
use std::collections::HashMap;
104104
use std::fs;
105105
use std::io::ErrorKind;
106106
use std::path::Path;
@@ -574,8 +574,7 @@ impl<'cfg> RegistryIndex<'cfg> {
574574
name: InternedString,
575575
req: &OptVersionReq,
576576
load: &mut dyn RegistryData,
577-
yanked_whitelist: &HashSet<PackageId>,
578-
f: &mut dyn FnMut(Summary),
577+
f: &mut dyn FnMut(IndexSummary),
579578
) -> Poll<CargoResult<()>> {
580579
if self.config.offline() {
581580
// This should only return `Poll::Ready(Ok(()))` if there is at least 1 match.
@@ -592,31 +591,15 @@ impl<'cfg> RegistryIndex<'cfg> {
592591
let callback = &mut |s: IndexSummary| {
593592
if !s.is_offline() {
594593
called = true;
595-
f(s.into_summary());
594+
f(s);
596595
}
597596
};
598-
ready!(self.query_inner_with_online(
599-
name,
600-
req,
601-
load,
602-
yanked_whitelist,
603-
callback,
604-
false
605-
)?);
597+
ready!(self.query_inner_with_online(name, req, load, callback, false)?);
606598
if called {
607599
return Poll::Ready(Ok(()));
608600
}
609601
}
610-
self.query_inner_with_online(
611-
name,
612-
req,
613-
load,
614-
yanked_whitelist,
615-
&mut |s| {
616-
f(s.into_summary());
617-
},
618-
true,
619-
)
602+
self.query_inner_with_online(name, req, load, f, true)
620603
}
621604

622605
/// Inner implementation of [`Self::query_inner`]. Returns the number of
@@ -628,7 +611,6 @@ impl<'cfg> RegistryIndex<'cfg> {
628611
name: InternedString,
629612
req: &OptVersionReq,
630613
load: &mut dyn RegistryData,
631-
yanked_whitelist: &HashSet<PackageId>,
632614
f: &mut dyn FnMut(IndexSummary),
633615
online: bool,
634616
) -> Poll<CargoResult<()>> {
@@ -650,10 +632,6 @@ impl<'cfg> RegistryIndex<'cfg> {
650632
IndexSummary::Offline(s.as_summary().clone())
651633
}
652634
})
653-
// Next filter out all yanked packages. Some yanked packages may
654-
// leak through if they're in a whitelist (aka if they were
655-
// previously in `Cargo.lock`
656-
.filter(|s| !s.is_yanked() || yanked_whitelist.contains(&s.package_id()))
657635
.for_each(f);
658636
Poll::Ready(Ok(()))
659637
}

src/cargo/sources/registry/mod.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -730,18 +730,15 @@ impl<'cfg> Source for RegistrySource<'cfg> {
730730
if kind == QueryKind::Exact && req.is_locked() && !self.ops.is_updated() {
731731
debug!("attempting query without update");
732732
let mut called = false;
733-
ready!(self.index.query_inner(
734-
dep.package_name(),
735-
&req,
736-
&mut *self.ops,
737-
&self.yanked_whitelist,
738-
&mut |s| {
739-
if dep.matches(&s) {
733+
ready!(self
734+
.index
735+
.query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| {
736+
if dep.matches(s.as_summary()) {
737+
// We are looking for a package from a lock file so we do not care about yank
740738
called = true;
741-
f(s);
739+
f(s.into_summary());
742740
}
743-
},
744-
))?;
741+
},))?;
745742
if called {
746743
Poll::Ready(Ok(()))
747744
} else {
@@ -751,22 +748,23 @@ impl<'cfg> Source for RegistrySource<'cfg> {
751748
}
752749
} else {
753750
let mut called = false;
754-
ready!(self.index.query_inner(
755-
dep.package_name(),
756-
&req,
757-
&mut *self.ops,
758-
&self.yanked_whitelist,
759-
&mut |s| {
751+
ready!(self
752+
.index
753+
.query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| {
760754
let matched = match kind {
761-
QueryKind::Exact => dep.matches(&s),
755+
QueryKind::Exact => dep.matches(s.as_summary()),
762756
QueryKind::Fuzzy => true,
763757
};
764-
if matched {
765-
f(s);
758+
// Next filter out all yanked packages. Some yanked packages may
759+
// leak through if they're in a whitelist (aka if they were
760+
// previously in `Cargo.lock`
761+
if matched
762+
&& (!s.is_yanked() || self.yanked_whitelist.contains(&s.package_id()))
763+
{
764+
f(s.into_summary());
766765
called = true;
767766
}
768-
}
769-
))?;
767+
}))?;
770768
if called {
771769
return Poll::Ready(Ok(()));
772770
}
@@ -788,13 +786,9 @@ impl<'cfg> Source for RegistrySource<'cfg> {
788786
}
789787
any_pending |= self
790788
.index
791-
.query_inner(
792-
name_permutation,
793-
&req,
794-
&mut *self.ops,
795-
&self.yanked_whitelist,
796-
f,
797-
)?
789+
.query_inner(name_permutation, &req, &mut *self.ops, &mut |s| {
790+
f(s.into_summary());
791+
})?
798792
.is_pending();
799793
}
800794
}

0 commit comments

Comments
 (0)