Skip to content

Commit

Permalink
Auto merge of #14418 - Rustin170506:rustin-patch-info-owners, r=weiha…
Browse files Browse the repository at this point in the history
…nglo

fix: remove list owners feature of info subcommand
  • Loading branch information
bors committed Aug 18, 2024
2 parents 4494032 + 866afb2 commit 8b04759
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 108 deletions.
67 changes: 1 addition & 66 deletions src/cargo/ops/registry/info/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Implementation of `cargo info`.
use anyhow::bail;
use cargo_credential::Operation;
use cargo_util_schemas::core::{PackageIdSpec, PartialVersion};
use crates_io::User;

use crate::core::registry::PackageRegistry;
use crate::core::{Dependency, Package, PackageId, PackageIdSpecQuery, Registry, Workspace};
Expand All @@ -12,7 +10,6 @@ use crate::ops::registry::{get_source_id_with_package_id, RegistryOrIndex, Regis
use crate::ops::resolve_ws;
use crate::sources::source::QueryKind;
use crate::sources::{IndexSummary, SourceConfigMap};
use crate::util::auth::AuthorizationErrorReason;
use crate::util::cache_lock::CacheLockMode;
use crate::util::command_prelude::root_manifest;
use crate::{CargoResult, GlobalContext};
Expand Down Expand Up @@ -79,19 +76,7 @@ pub fn info(

let package = registry.get(&[package_id])?;
let package = package.get_one(package_id)?;
let owners = try_list_owners(
gctx,
&source_ids,
reg_or_index.as_ref(),
package_id.name().as_str(),
)?;
pretty_view(
package,
&summaries,
&owners,
suggest_cargo_tree_command,
gctx,
)?;
pretty_view(package, &summaries, suggest_cargo_tree_command, gctx)?;

Ok(())
}
Expand Down Expand Up @@ -207,56 +192,6 @@ fn query_summaries(
}
}

// Try to list the login and name of all owners of a crate.
fn try_list_owners(
gctx: &GlobalContext,
source_ids: &RegistrySourceIds,
reg_or_index: Option<&RegistryOrIndex>,
package_name: &str,
) -> CargoResult<Option<Vec<String>>> {
// Only remote registries support listing owners.
if !source_ids.original.is_remote_registry() {
return Ok(None);
}
match super::registry(
gctx,
source_ids,
None,
reg_or_index,
false,
Some(Operation::Read),
) {
Ok(mut registry) => {
let owners = registry.list_owners(package_name)?;
let names = owners.iter().map(get_username).collect();
return Ok(Some(names));
}
Err(err) => {
// If the token is missing, it means the user is not logged in.
// We don't want to show an error in this case.
if err.to_string().contains(
(AuthorizationErrorReason::TokenMissing)
.to_string()
.as_str(),
) {
return Ok(None);
}
return Err(err);
}
}
}

fn get_username(u: &User) -> String {
format!(
"{}{}",
u.login,
u.name
.as_ref()
.map(|name| format!(" ({})", name))
.unwrap_or_default(),
)
}

fn validate_locked_and_frozen_options(
in_workspace: bool,
gctx: &GlobalContext,
Expand Down
18 changes: 0 additions & 18 deletions src/cargo/ops/registry/info/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::{
pub(super) fn pretty_view(
package: &Package,
summaries: &[IndexSummary],
owners: &Option<Vec<String>>,
suggest_cargo_tree_command: bool,
gctx: &GlobalContext,
) -> CargoResult<()> {
Expand Down Expand Up @@ -153,10 +152,6 @@ pub(super) fn pretty_view(
gctx,
)?;

if let Some(owners) = owners {
pretty_owners(owners, stdout)?;
}

if suggest_cargo_tree_command {
suggest_cargo_tree(package_id, stdout)?;
}
Expand Down Expand Up @@ -399,19 +394,6 @@ fn pretty_features(
Ok(())
}

fn pretty_owners(owners: &Vec<String>, stdout: &mut dyn Write) -> CargoResult<()> {
let header = HEADER;

if !owners.is_empty() {
writeln!(stdout, "{header}owners:{header:#}",)?;
for owner in owners {
writeln!(stdout, " {}", owner)?;
}
}

Ok(())
}

// Suggest the cargo tree command to view the dependency tree.
fn suggest_cargo_tree(package_id: PackageId, stdout: &mut dyn Write) -> CargoResult<()> {
let literal = LITERAL;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions tests/testsuite/cargo_info/verbose/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions tests/testsuite/cargo_info/within_ws/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8b04759

Please sign in to comment.