Skip to content

Commit

Permalink
Auto merge of #12290 - weihanglo:refactor-registry-api, r=epage
Browse files Browse the repository at this point in the history
refactor(registry): extract and rearrange items to their own modules
  • Loading branch information
bors committed Jun 24, 2023
2 parents 03bc66b + aaf0221 commit 5febbe5
Show file tree
Hide file tree
Showing 19 changed files with 1,553 additions and 1,374 deletions.
6 changes: 4 additions & 2 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![allow(clippy::all)]
#![warn(clippy::disallowed_methods)]

use cargo::util::network::http::http_handle;
use cargo::util::network::http::needs_custom_http_transport;
use cargo::util::toml::StringOrVec;
use cargo::util::CliError;
use cargo::util::{self, closest_msg, command_prelude, CargoResult, CliResult, Config};
Expand Down Expand Up @@ -293,12 +295,12 @@ fn init_git(config: &Config) {
/// configured to use libcurl instead of the built-in networking support so
/// that those configuration settings can be used.
fn init_git_transports(config: &Config) {
match cargo::ops::needs_custom_http_transport(config) {
match needs_custom_http_transport(config) {
Ok(true) => {}
_ => return,
}

let handle = match cargo::ops::http_handle(config) {
let handle = match http_handle(config) {
Ok(handle) => handle,
Err(..) => return,
};
Expand Down
9 changes: 5 additions & 4 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ use crate::core::resolver::{HasDevUnits, Resolve};
use crate::core::source::MaybePackage;
use crate::core::{Dependency, Manifest, PackageId, SourceId, Target};
use crate::core::{SourceMap, Summary, Workspace};
use crate::ops;
use crate::util::config::PackageCacheLock;
use crate::util::errors::{CargoResult, HttpNotSuccessful, DEBUG_HEADERS};
use crate::util::interning::InternedString;
use crate::util::network::http::http_handle_and_timeout;
use crate::util::network::http::HttpTimeout;
use crate::util::network::retry::{Retry, RetryResult};
use crate::util::network::sleep::SleepTracker;
use crate::util::{self, internal, Config, Progress, ProgressStyle};
Expand Down Expand Up @@ -348,7 +349,7 @@ pub struct Downloads<'a, 'cfg> {
/// Note that timeout management is done manually here instead of in libcurl
/// because we want to apply timeouts to an entire batch of operations, not
/// any one particular single operation.
timeout: ops::HttpTimeout,
timeout: HttpTimeout,
/// Last time bytes were received.
updated_at: Cell<Instant>,
/// This is a slow-speed check. It is reset to `now + timeout_duration`
Expand Down Expand Up @@ -441,7 +442,7 @@ impl<'cfg> PackageSet<'cfg> {

pub fn enable_download<'a>(&'a self) -> CargoResult<Downloads<'a, 'cfg>> {
assert!(!self.downloading.replace(true));
let timeout = ops::HttpTimeout::new(self.config)?;
let timeout = HttpTimeout::new(self.config)?;
Ok(Downloads {
start: Instant::now(),
set: self,
Expand Down Expand Up @@ -713,7 +714,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
debug!("downloading {} as {}", id, token);
assert!(self.pending_ids.insert(id));

let (mut handle, _timeout) = ops::http_handle_and_timeout(self.set.config)?;
let (mut handle, _timeout) = http_handle_and_timeout(self.set.config)?;
handle.get(true)?;
handle.url(&url)?;
handle.follow_location(true)?; // follow redirects
Expand Down
14 changes: 9 additions & 5 deletions src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ pub use self::cargo_test::{run_benches, run_tests, TestOptions};
pub use self::cargo_uninstall::uninstall;
pub use self::fix::{fix, fix_exec_rustc, fix_get_proxy_lock_addr, FixOptions};
pub use self::lockfile::{load_pkg_lockfile, resolve_to_string, write_pkg_lockfile};
pub use self::registry::HttpTimeout;
pub use self::registry::{configure_http_handle, http_handle, http_handle_and_timeout};
pub use self::registry::{modify_owners, yank, OwnersOptions, PublishOpts};
pub use self::registry::{needs_custom_http_transport, registry_login, registry_logout, search};
pub use self::registry::{publish, RegistryCredentialConfig};
pub use self::registry::modify_owners;
pub use self::registry::publish;
pub use self::registry::registry_login;
pub use self::registry::registry_logout;
pub use self::registry::search;
pub use self::registry::yank;
pub use self::registry::OwnersOptions;
pub use self::registry::PublishOpts;
pub use self::registry::RegistryCredentialConfig;
pub use self::resolve::{
add_overrides, get_resolved_packages, resolve_with_previous, resolve_ws, resolve_ws_with_opts,
WorkspaceResolve,
Expand Down
Loading

0 comments on commit 5febbe5

Please sign in to comment.