Skip to content

Commit 0a84f1f

Browse files
committed
refactor(registry): Expose the registry source for reuse
1 parent e0a1918 commit 0a84f1f

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

src/cargo/ops/registry/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn registry_login(
3434
false,
3535
None,
3636
) {
37-
Ok(registry) => Some(format!("{}/me", registry.host())),
37+
Ok((registry, _)) => Some(format!("{}/me", registry.host())),
3838
Err(e) if e.is::<AuthorizationError>() => e
3939
.downcast::<AuthorizationError>()
4040
.unwrap()

src/cargo/ops/registry/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ impl RegistryCredentialConfig {
120120
/// `registry`, or `index` are set, then uses `crates-io`.
121121
/// * `force_update`: If `true`, forces the index to be updated.
122122
/// * `token_required`: If `true`, the token will be set.
123-
fn registry(
124-
gctx: &GlobalContext,
123+
fn registry<'gctx>(
124+
gctx: &'gctx GlobalContext,
125125
source_ids: &RegistrySourceIds,
126126
token_from_cmdline: Option<Secret<&str>>,
127127
reg_or_index: Option<&RegistryOrIndex>,
128128
force_update: bool,
129129
token_required: Option<Operation<'_>>,
130-
) -> CargoResult<Registry> {
130+
) -> CargoResult<(Registry, RegistrySource<'gctx>)> {
131131
let is_index = reg_or_index.map(|v| v.is_index()).unwrap_or_default();
132132
if is_index && token_required.is_some() && token_from_cmdline.is_none() {
133133
bail!("command-line argument --index requires --token to be specified");
@@ -136,9 +136,9 @@ fn registry(
136136
auth::cache_token_from_commandline(gctx, &source_ids.original, token);
137137
}
138138

139+
let mut src = RegistrySource::remote(source_ids.replacement, &HashSet::new(), gctx)?;
139140
let cfg = {
140141
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
141-
let mut src = RegistrySource::remote(source_ids.replacement, &HashSet::new(), gctx)?;
142142
// Only update the index if `force_update` is set.
143143
if force_update {
144144
src.invalidate_cache()
@@ -170,11 +170,9 @@ fn registry(
170170
None
171171
};
172172
let handle = http_handle(gctx)?;
173-
Ok(Registry::new_handle(
174-
api_host,
175-
token,
176-
handle,
177-
cfg.auth_required,
173+
Ok((
174+
Registry::new_handle(api_host, token, handle, cfg.auth_required),
175+
src,
178176
))
179177
}
180178

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
let source_ids = super::get_source_id(gctx, opts.reg_or_index.as_ref())?;
39-
let mut registry = super::registry(
39+
let (mut registry, _) = super::registry(
4040
gctx,
4141
&source_ids,
4242
opts.token.as_ref().map(Secret::as_deref),

src/cargo/ops/registry/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
115115
// This is only used to confirm that we can create a token before we build the package.
116116
// This causes the credential provider to be called an extra time, but keeps the same order of errors.
117117
let source_ids = super::get_source_id(opts.gctx, reg_or_index.as_ref())?;
118-
let mut registry = super::registry(
118+
let (mut registry, _) = super::registry(
119119
opts.gctx,
120120
&source_ids,
121121
opts.token.as_ref().map(Secret::as_deref),

src/cargo/ops/registry/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn search(
2121
limit: u32,
2222
) -> CargoResult<()> {
2323
let source_ids = super::get_source_id(gctx, reg_or_index.as_ref())?;
24-
let mut registry =
24+
let (mut registry, _) =
2525
super::registry(gctx, &source_ids, None, reg_or_index.as_ref(), false, None)?;
2626
let (crates, total_crates) = registry.search(query, limit).with_context(|| {
2727
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
let source_ids = super::get_source_id(gctx, reg_or_index.as_ref())?;
50-
let mut registry = super::registry(
50+
let (mut registry, _) = super::registry(
5151
gctx,
5252
&source_ids,
5353
token.as_ref().map(Secret::as_deref),

0 commit comments

Comments
 (0)