Skip to content

Commit 57b9372

Browse files
committed
move yank handling up
1 parent dff1874 commit 57b9372

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
@@ -99,7 +99,7 @@ use semver::Version;
9999
use serde::Deserialize;
100100
use std::borrow::Cow;
101101
use std::collections::BTreeMap;
102-
use std::collections::{HashMap, HashSet};
102+
use std::collections::HashMap;
103103
use std::fs;
104104
use std::io::ErrorKind;
105105
use std::path::Path;
@@ -573,8 +573,7 @@ impl<'cfg> RegistryIndex<'cfg> {
573573
name: InternedString,
574574
req: &OptVersionReq,
575575
load: &mut dyn RegistryData,
576-
yanked_whitelist: &HashSet<PackageId>,
577-
f: &mut dyn FnMut(Summary),
576+
f: &mut dyn FnMut(IndexSummary),
578577
) -> Poll<CargoResult<()>> {
579578
if self.config.offline() {
580579
// This should only return `Poll::Ready(Ok(()))` if there is at least 1 match.
@@ -591,31 +590,15 @@ impl<'cfg> RegistryIndex<'cfg> {
591590
let callback = &mut |s: IndexSummary| {
592591
if !s.is_offline() {
593592
called = true;
594-
f(s.into_summary());
593+
f(s);
595594
}
596595
};
597-
ready!(self.query_inner_with_online(
598-
name,
599-
req,
600-
load,
601-
yanked_whitelist,
602-
callback,
603-
false
604-
)?);
596+
ready!(self.query_inner_with_online(name, req, load, callback, false)?);
605597
if called {
606598
return Poll::Ready(Ok(()));
607599
}
608600
}
609-
self.query_inner_with_online(
610-
name,
611-
req,
612-
load,
613-
yanked_whitelist,
614-
&mut |s| {
615-
f(s.into_summary());
616-
},
617-
true,
618-
)
601+
self.query_inner_with_online(name, req, load, f, true)
619602
}
620603

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

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)