Skip to content

Commit 6aad5ec

Browse files
committed
Pull Request feedback
1 parent f12f025 commit 6aad5ec

File tree

9 files changed

+224
-234
lines changed

9 files changed

+224
-234
lines changed

src/cargo/core/registry.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
637637
let source = self.sources.get_mut(dep.source_id());
638638
match (override_summary, source) {
639639
(Some(_), None) => {
640-
return Err(anyhow::anyhow!("override found but no real ones")).into()
640+
return Poll::Ready(Err(anyhow::anyhow!("override found but no real ones")))
641641
}
642642
(None, None) => return Poll::Ready(Ok(())),
643643

@@ -678,8 +678,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
678678
// the summaries it gives us though.
679679
(Some(override_summary), Some(source)) => {
680680
if !patches.is_empty() {
681-
return Err(anyhow::anyhow!("found patches and a path override"))
682-
.into();
681+
return Poll::Ready(Err(anyhow::anyhow!("found patches and a path override")))
683682
}
684683
let mut n = 0;
685684
let mut to_warn = None;
@@ -704,7 +703,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
704703
};
705704

706705
if n > 1 {
707-
return Err(anyhow::anyhow!("found an override with a non-locked list")).into();
706+
return Poll::Ready(Err(anyhow::anyhow!("found an override with a non-locked list")))
708707
} else if let Some(summary) = to_warn {
709708
self.warn_bad_override(&override_summary, &summary)?;
710709
}
@@ -865,7 +864,7 @@ fn summary_for_patch(
865864
let mut vers: Vec<_> = summaries.iter().map(|summary| summary.version()).collect();
866865
vers.sort();
867866
let versions: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
868-
return Err(anyhow::anyhow!(
867+
return Poll::Ready(Err(anyhow::anyhow!(
869868
"patch for `{}` in `{}` resolved to more than one candidate\n\
870869
Found versions: {}\n\
871870
Update the patch definition to select only one package.\n\
@@ -875,8 +874,7 @@ fn summary_for_patch(
875874
orig_patch.source_id(),
876875
versions.join(", "),
877876
versions.last().unwrap()
878-
))
879-
.into();
877+
)))
880878
}
881879
assert!(summaries.is_empty());
882880
// No summaries found, try to help the user figure out what is wrong.
@@ -932,7 +930,7 @@ fn summary_for_patch(
932930
format!("versions `{}`", strs.join(", "))
933931
}
934932
};
935-
Err(if found.is_empty() {
933+
Poll::Ready(Err(if found.is_empty() {
936934
anyhow::anyhow!(
937935
"The patch location `{}` does not appear to contain any packages \
938936
matching the name `{}`.",
@@ -950,6 +948,5 @@ fn summary_for_patch(
950948
found,
951949
orig_patch.version_req()
952950
)
953-
})
954-
.into()
951+
}))
955952
}

src/cargo/core/source/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ pub trait Source {
105105
/// as yanked. This ignores the yanked whitelist.
106106
fn is_yanked(&mut self, _pkg: PackageId) -> CargoResult<bool>;
107107

108-
/// Block until all outstanding Poll::Pending requests are Poll::Ready.
108+
/// Block until all outstanding Poll::Pending requests are `Poll::Ready`.
109+
///
110+
/// After calling this function, the source should return `Poll::Ready` for
111+
/// any queries that previously returned `Poll::Pending`.
112+
///
113+
/// If no queries previously returned `Poll::Pending`, and `invalidate_cache`
114+
/// was not called, this function should be a no-op.
109115
fn block_until_ready(&mut self) -> CargoResult<()>;
110116
}
111117

src/cargo/sources/directory.rs

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,58 @@ impl<'cfg> DirectorySource<'cfg> {
3737
updated: false,
3838
}
3939
}
40+
}
41+
42+
impl<'cfg> Debug for DirectorySource<'cfg> {
43+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
44+
write!(f, "DirectorySource {{ root: {:?} }}", self.root)
45+
}
46+
}
47+
48+
impl<'cfg> Source for DirectorySource<'cfg> {
49+
fn query(&mut self, dep: &Dependency, f: &mut dyn FnMut(Summary)) -> Poll<CargoResult<()>> {
50+
if !self.updated {
51+
return Poll::Pending;
52+
}
53+
let packages = self.packages.values().map(|p| &p.0);
54+
let matches = packages.filter(|pkg| dep.matches(pkg.summary()));
55+
for summary in matches.map(|pkg| pkg.summary().clone()) {
56+
f(summary);
57+
}
58+
Poll::Ready(Ok(()))
59+
}
4060

41-
fn update(&mut self) -> CargoResult<()> {
61+
fn fuzzy_query(
62+
&mut self,
63+
_dep: &Dependency,
64+
f: &mut dyn FnMut(Summary),
65+
) -> Poll<CargoResult<()>> {
66+
if !self.updated {
67+
return Poll::Pending;
68+
}
69+
let packages = self.packages.values().map(|p| &p.0);
70+
for summary in packages.map(|pkg| pkg.summary().clone()) {
71+
f(summary);
72+
}
73+
Poll::Ready(Ok(()))
74+
}
75+
76+
fn supports_checksums(&self) -> bool {
77+
true
78+
}
79+
80+
fn requires_precise(&self) -> bool {
81+
true
82+
}
83+
84+
fn source_id(&self) -> SourceId {
85+
self.source_id
86+
}
87+
88+
fn block_until_ready(&mut self) -> CargoResult<()> {
89+
if self.updated {
90+
return Ok(());
91+
}
4292
self.packages.clear();
4393
let entries = self.root.read_dir().with_context(|| {
4494
format!(
@@ -109,55 +159,9 @@ impl<'cfg> DirectorySource<'cfg> {
109159
self.packages.insert(pkg.package_id(), (pkg, cksum));
110160
}
111161

162+
self.updated = true;
112163
Ok(())
113164
}
114-
}
115-
116-
impl<'cfg> Debug for DirectorySource<'cfg> {
117-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
118-
write!(f, "DirectorySource {{ root: {:?} }}", self.root)
119-
}
120-
}
121-
122-
impl<'cfg> Source for DirectorySource<'cfg> {
123-
fn query(&mut self, dep: &Dependency, f: &mut dyn FnMut(Summary)) -> Poll<CargoResult<()>> {
124-
if !self.updated {
125-
return Poll::Pending;
126-
}
127-
let packages = self.packages.values().map(|p| &p.0);
128-
let matches = packages.filter(|pkg| dep.matches(pkg.summary()));
129-
for summary in matches.map(|pkg| pkg.summary().clone()) {
130-
f(summary);
131-
}
132-
Poll::Ready(Ok(()))
133-
}
134-
135-
fn fuzzy_query(
136-
&mut self,
137-
_dep: &Dependency,
138-
f: &mut dyn FnMut(Summary),
139-
) -> Poll<CargoResult<()>> {
140-
if !self.updated {
141-
return Poll::Pending;
142-
}
143-
let packages = self.packages.values().map(|p| &p.0);
144-
for summary in packages.map(|pkg| pkg.summary().clone()) {
145-
f(summary);
146-
}
147-
Poll::Ready(Ok(()))
148-
}
149-
150-
fn supports_checksums(&self) -> bool {
151-
true
152-
}
153-
154-
fn requires_precise(&self) -> bool {
155-
true
156-
}
157-
158-
fn source_id(&self) -> SourceId {
159-
self.source_id
160-
}
161165

162166
fn download(&mut self, id: PackageId) -> CargoResult<MaybePackage> {
163167
self.packages
@@ -219,11 +223,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {
219223
Ok(false)
220224
}
221225

222-
fn block_until_ready(&mut self) -> CargoResult<()> {
223-
self.update()?;
224-
self.updated = true;
225-
Ok(())
226+
fn invalidate_cache(&mut self) {
227+
// Path source has no local cache.
226228
}
227-
228-
fn invalidate_cache(&mut self) {}
229229
}

src/cargo/sources/git/source.rs

Lines changed: 66 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub struct GitSource<'cfg> {
2020
path_source: Option<PathSource<'cfg>>,
2121
ident: String,
2222
config: &'cfg Config,
23-
updated: bool,
2423
}
2524

2625
impl<'cfg> GitSource<'cfg> {
@@ -43,7 +42,6 @@ impl<'cfg> GitSource<'cfg> {
4342
path_source: None,
4443
ident,
4544
config,
46-
updated: false,
4745
};
4846

4947
Ok(source)
@@ -55,13 +53,72 @@ impl<'cfg> GitSource<'cfg> {
5553

5654
pub fn read_packages(&mut self) -> CargoResult<Vec<Package>> {
5755
if self.path_source.is_none() {
58-
self.update()?;
56+
self.invalidate_cache();
57+
self.block_until_ready()?;
5958
}
6059
self.path_source.as_mut().unwrap().read_packages()
6160
}
61+
}
62+
63+
fn ident(id: &SourceId) -> String {
64+
let ident = id
65+
.canonical_url()
66+
.raw_canonicalized_url()
67+
.path_segments()
68+
.and_then(|s| s.rev().next())
69+
.unwrap_or("");
70+
71+
let ident = if ident.is_empty() { "_empty" } else { ident };
72+
73+
format!("{}-{}", ident, short_hash(id.canonical_url()))
74+
}
6275

63-
fn update(&mut self) -> CargoResult<()> {
64-
if self.updated {
76+
impl<'cfg> Debug for GitSource<'cfg> {
77+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
78+
write!(f, "git repo at {}", self.remote.url())?;
79+
80+
match self.manifest_reference.pretty_ref() {
81+
Some(s) => write!(f, " ({})", s),
82+
None => Ok(()),
83+
}
84+
}
85+
}
86+
87+
impl<'cfg> Source for GitSource<'cfg> {
88+
fn query(&mut self, dep: &Dependency, f: &mut dyn FnMut(Summary)) -> Poll<CargoResult<()>> {
89+
if let Some(src) = self.path_source.as_mut() {
90+
src.query(dep, f)
91+
} else {
92+
Poll::Pending
93+
}
94+
}
95+
96+
fn fuzzy_query(
97+
&mut self,
98+
dep: &Dependency,
99+
f: &mut dyn FnMut(Summary),
100+
) -> Poll<CargoResult<()>> {
101+
if let Some(src) = self.path_source.as_mut() {
102+
src.fuzzy_query(dep, f)
103+
} else {
104+
Poll::Pending
105+
}
106+
}
107+
108+
fn supports_checksums(&self) -> bool {
109+
false
110+
}
111+
112+
fn requires_precise(&self) -> bool {
113+
true
114+
}
115+
116+
fn source_id(&self) -> SourceId {
117+
self.source_id
118+
}
119+
120+
fn block_until_ready(&mut self) -> CargoResult<()> {
121+
if self.path_source.is_some() {
65122
return Ok(());
66123
}
67124

@@ -92,10 +149,10 @@ impl<'cfg> GitSource<'cfg> {
92149
// doesn't have it.
93150
(locked_rev, db) => {
94151
if self.config.offline() {
95-
return Err(anyhow::anyhow!(
152+
anyhow::bail!(
96153
"can't checkout from '{}': you are in the offline mode (--offline)",
97154
self.remote.url()
98-
));
155+
);
99156
}
100157
self.config.shell().status(
101158
"Updating",
@@ -133,67 +190,7 @@ impl<'cfg> GitSource<'cfg> {
133190

134191
self.path_source = Some(path_source);
135192
self.locked_rev = Some(actual_rev);
136-
self.path_source.as_mut().unwrap().update()?;
137-
self.updated = true;
138-
Ok(())
139-
}
140-
}
141-
142-
fn ident(id: &SourceId) -> String {
143-
let ident = id
144-
.canonical_url()
145-
.raw_canonicalized_url()
146-
.path_segments()
147-
.and_then(|s| s.rev().next())
148-
.unwrap_or("");
149-
150-
let ident = if ident.is_empty() { "_empty" } else { ident };
151-
152-
format!("{}-{}", ident, short_hash(id.canonical_url()))
153-
}
154-
155-
impl<'cfg> Debug for GitSource<'cfg> {
156-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
157-
write!(f, "git repo at {}", self.remote.url())?;
158-
159-
match self.manifest_reference.pretty_ref() {
160-
Some(s) => write!(f, " ({})", s),
161-
None => Ok(()),
162-
}
163-
}
164-
}
165-
166-
impl<'cfg> Source for GitSource<'cfg> {
167-
fn query(&mut self, dep: &Dependency, f: &mut dyn FnMut(Summary)) -> Poll<CargoResult<()>> {
168-
if let Some(src) = self.path_source.as_mut() {
169-
src.query(dep, f)
170-
} else {
171-
Poll::Pending
172-
}
173-
}
174-
175-
fn fuzzy_query(
176-
&mut self,
177-
dep: &Dependency,
178-
f: &mut dyn FnMut(Summary),
179-
) -> Poll<CargoResult<()>> {
180-
if let Some(src) = self.path_source.as_mut() {
181-
src.fuzzy_query(dep, f)
182-
} else {
183-
Poll::Pending
184-
}
185-
}
186-
187-
fn supports_checksums(&self) -> bool {
188-
false
189-
}
190-
191-
fn requires_precise(&self) -> bool {
192-
true
193-
}
194-
195-
fn source_id(&self) -> SourceId {
196-
self.source_id
193+
self.path_source.as_mut().unwrap().update()
197194
}
198195

199196
fn download(&mut self, id: PackageId) -> CargoResult<MaybePackage> {
@@ -226,13 +223,7 @@ impl<'cfg> Source for GitSource<'cfg> {
226223
Ok(false)
227224
}
228225

229-
fn block_until_ready(&mut self) -> CargoResult<()> {
230-
self.update()
231-
}
232-
233-
fn invalidate_cache(&mut self) {
234-
self.updated = false;
235-
}
226+
fn invalidate_cache(&mut self) {}
236227
}
237228

238229
#[cfg(test)]

0 commit comments

Comments
 (0)