Skip to content

Commit ef215c7

Browse files
committed
Fix duplicate updating messages when using alt registries by reusing the RegistrySource.
1 parent 3baf514 commit ef215c7

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

src/cargo/ops/registry/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn registry_login(
2727
let source_ids = get_source_id(gctx, reg_or_index)?;
2828

2929
let login_url = match registry(gctx, token_from_cmdline.clone(), reg_or_index, false, None) {
30-
Ok((registry, _)) => Some(format!("{}/me", registry.host())),
30+
Ok((registry, _, _)) => Some(format!("{}/me", registry.host())),
3131
Err(e) if e.is::<AuthorizationError>() => e
3232
.downcast::<AuthorizationError>()
3333
.unwrap()

src/cargo/ops/registry/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ impl RegistryCredentialConfig {
114114
/// `registry`, or `index` are set, then uses `crates-io`.
115115
/// * `force_update`: If `true`, forces the index to be updated.
116116
/// * `token_required`: If `true`, the token will be set.
117-
fn registry(
118-
gctx: &GlobalContext,
117+
fn registry<'gctx>(
118+
gctx: &'gctx GlobalContext,
119119
token_from_cmdline: Option<Secret<&str>>,
120120
reg_or_index: Option<&RegistryOrIndex>,
121121
force_update: bool,
122122
token_required: Option<Operation<'_>>,
123-
) -> CargoResult<(Registry, RegistrySourceIds)> {
123+
) -> CargoResult<(Registry, RegistrySourceIds, RegistrySource<'gctx>)> {
124124
let source_ids = get_source_id(gctx, reg_or_index)?;
125125

126126
let is_index = reg_or_index.map(|v| v.is_index()).unwrap_or_default();
@@ -131,9 +131,9 @@ fn registry(
131131
auth::cache_token_from_commandline(gctx, &source_ids.original, token);
132132
}
133133

134+
let mut src = RegistrySource::remote(source_ids.replacement, &HashSet::new(), gctx)?;
134135
let cfg = {
135136
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
136-
let mut src = RegistrySource::remote(source_ids.replacement, &HashSet::new(), gctx)?;
137137
// Only update the index if `force_update` is set.
138138
if force_update {
139139
src.invalidate_cache()
@@ -168,6 +168,7 @@ fn registry(
168168
Ok((
169169
Registry::new_handle(api_host, token, handle, cfg.auth_required),
170170
source_ids,
171+
src,
171172
))
172173
}
173174

src/cargo/ops/registry/owner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn modify_owners(gctx: &GlobalContext, opts: &OwnersOptions) -> CargoResult<
3636

3737
let operation = Operation::Owners { name: &name };
3838

39-
let (mut registry, _) = super::registry(
39+
let (mut registry, _, _) = super::registry(
4040
gctx,
4141
opts.token.as_ref().map(Secret::as_deref),
4242
opts.reg_or_index.as_ref(),

src/cargo/ops/registry/publish.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::ops;
2828
use crate::ops::PackageOpts;
2929
use crate::ops::Packages;
3030
use crate::sources::source::QueryKind;
31+
use crate::sources::source::Source;
3132
use crate::sources::SourceConfigMap;
3233
use crate::sources::CRATES_IO_REGISTRY;
3334
use crate::util::auth;
@@ -127,7 +128,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
127128
}
128129
val => val,
129130
};
130-
let (mut registry, reg_ids) = super::registry(
131+
let (mut registry, reg_ids, mut source) = super::registry(
131132
opts.gctx,
132133
opts.token.as_ref().map(Secret::as_deref),
133134
reg_or_index.as_ref(),
@@ -138,9 +139,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
138139

139140
// Bail before packaging and uploading if same version already exists in the registry
140141

141-
let mut source = SourceConfigMap::empty(opts.gctx)?.load(reg_ids.original, &HashSet::new())?;
142-
143-
let query = Dependency::parse(pkg.name(), Some(&ver), reg_ids.original)?;
142+
let query = Dependency::parse(pkg.name(), Some(&ver), reg_ids.replacement)?;
144143

145144
let _lock = opts
146145
.gctx

src/cargo/ops/registry/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn search(
2020
reg_or_index: Option<RegistryOrIndex>,
2121
limit: u32,
2222
) -> CargoResult<()> {
23-
let (mut registry, source_ids) =
23+
let (mut registry, source_ids, _) =
2424
super::registry(gctx, None, reg_or_index.as_ref(), false, None)?;
2525
let (crates, total_crates) = registry.search(query, limit).with_context(|| {
2626
format!(

src/cargo/ops/registry/yank.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn yank(
4747
}
4848
};
4949

50-
let (mut registry, _) = super::registry(
50+
let (mut registry, _, _) = super::registry(
5151
gctx,
5252
token.as_ref().map(Secret::as_deref),
5353
reg_or_index.as_ref(),

0 commit comments

Comments
 (0)