Skip to content

Commit

Permalink
refactor(update): Consolidate status messages
Browse files Browse the repository at this point in the history
This builds on the prior work to consolidate everything, simplifying the
code and making it clearer what behavior differences exist between
change kinds.
  • Loading branch information
epage committed Aug 21, 2024
1 parent 2e1f9f4 commit bb1d830
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 100 deletions.
170 changes: 72 additions & 98 deletions src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,32 +501,39 @@ fn print_lockfile_generation(
status_locking(ws, num_pkgs)?;

for change in changes {
let possibilities = if let Some(query) = change.alternatives_query() {
loop {
match registry.query_vec(&query, QueryKind::Exact) {
std::task::Poll::Ready(res) => {
break res?;
match change.kind {
PackageChangeKind::Added => {
let possibilities = if let Some(query) = change.alternatives_query() {
loop {
match registry.query_vec(&query, QueryKind::Exact) {
std::task::Poll::Ready(res) => {
break res?;
}
std::task::Poll::Pending => registry.block_until_ready()?,
}
}
std::task::Poll::Pending => registry.block_until_ready()?,
}
}
} else {
vec![]
};
} else {
vec![]
};

{
let package_id = change.package_id;
let required_rust_version = report_required_rust_version(ws, resolve, package_id);
let latest = report_latest(&possibilities, package_id);
let note = required_rust_version.or(latest);
let package_id = change.package_id;
let required_rust_version = report_required_rust_version(ws, resolve, package_id);
let latest = report_latest(&possibilities, package_id);
let note = required_rust_version.or(latest);

if let Some(note) = note {
assert_eq!(change.kind, PackageChangeKind::Added);
ws.gctx().shell().status_with_color(
change.kind.status(),
format!("{change}{note}"),
&change.kind.style(),
)?;
if let Some(note) = note {
ws.gctx().shell().status_with_color(
change.kind.status(),
format!("{change}{note}"),
&change.kind.style(),
)?;
}
}
PackageChangeKind::Upgraded
| PackageChangeKind::Downgraded
| PackageChangeKind::Removed
| PackageChangeKind::Unchanged => {
unreachable!("without a previous resolve, everything should be added")
}
}
}
Expand All @@ -548,42 +555,24 @@ fn print_lockfile_sync(
status_locking(ws, num_pkgs)?;

for change in changes {
let possibilities = if let Some(query) = change.alternatives_query() {
loop {
match registry.query_vec(&query, QueryKind::Exact) {
std::task::Poll::Ready(res) => {
break res?;
match change.kind {
PackageChangeKind::Added
| PackageChangeKind::Upgraded
| PackageChangeKind::Downgraded => {
let possibilities = if let Some(query) = change.alternatives_query() {
loop {
match registry.query_vec(&query, QueryKind::Exact) {
std::task::Poll::Ready(res) => {
break res?;
}
std::task::Poll::Pending => registry.block_until_ready()?,
}
}
std::task::Poll::Pending => registry.block_until_ready()?,
}
}
} else {
vec![]
};

let package_id = change.package_id;
if change.previous_id.is_some() {
let required_rust_version = report_required_rust_version(ws, resolve, package_id);
let latest = report_latest(&possibilities, package_id);
let note = required_rust_version.or(latest).unwrap_or_default();

let msg = format!("{change}{note}");
} else {
vec![]
};

if change.kind == PackageChangeKind::Downgraded {
ws.gctx().shell().status_with_color(
change.kind.status(),
msg,
&change.kind.style(),
)?;
} else {
ws.gctx().shell().status_with_color(
change.kind.status(),
msg,
&change.kind.style(),
)?;
}
} else {
if change.kind == PackageChangeKind::Added {
let package_id = change.package_id;
let required_rust_version = report_required_rust_version(ws, resolve, package_id);
let latest = report_latest(&possibilities, package_id);
let note = required_rust_version.or(latest).unwrap_or_default();
Expand All @@ -594,6 +583,7 @@ fn print_lockfile_sync(
&change.kind.style(),
)?;
}
PackageChangeKind::Removed | PackageChangeKind::Unchanged => {}
}
}

Expand Down Expand Up @@ -628,61 +618,45 @@ fn print_lockfile_updates(
vec![]
};

let package_id = change.package_id;
if change.previous_id.is_some() {
let required_rust_version = report_required_rust_version(ws, resolve, package_id);
let latest = report_latest(&possibilities, package_id);
let note = required_rust_version.or(latest).unwrap_or_default();

let msg = format!("{change}{note}");
match change.kind {
PackageChangeKind::Added
| PackageChangeKind::Upgraded
| PackageChangeKind::Downgraded => {
let package_id = change.package_id;
let required_rust_version = report_required_rust_version(ws, resolve, package_id);
let latest = report_latest(&possibilities, package_id);
let note = required_rust_version.or(latest).unwrap_or_default();

if change.kind == PackageChangeKind::Downgraded {
ws.gctx().shell().status_with_color(
change.kind.status(),
msg,
&change.kind.style(),
)?;
} else {
ws.gctx().shell().status_with_color(
change.kind.status(),
msg,
format!("{change}{note}"),
&change.kind.style(),
)?;
}
} else {
if change.kind == PackageChangeKind::Removed {
PackageChangeKind::Removed => {
ws.gctx().shell().status_with_color(
change.kind.status(),
format!("{change}"),
&change.kind.style(),
)?;
} else if change.kind == PackageChangeKind::Added {
}
PackageChangeKind::Unchanged => {
let package_id = change.package_id;
let required_rust_version = report_required_rust_version(ws, resolve, package_id);
let latest = report_latest(&possibilities, package_id);
let note = required_rust_version.or(latest).unwrap_or_default();
let note = required_rust_version.as_deref().or(latest.as_deref());

ws.gctx().shell().status_with_color(
change.kind.status(),
format!("{change}{note}"),
&change.kind.style(),
)?;
}
}
if change.kind == PackageChangeKind::Unchanged {
let required_rust_version = report_required_rust_version(ws, resolve, package_id);
let latest = report_latest(&possibilities, package_id);
let note = required_rust_version.as_deref().or(latest.as_deref());

if let Some(note) = note {
if latest.is_some() {
unchanged_behind += 1;
}
if ws.gctx().shell().verbosity() == Verbosity::Verbose {
ws.gctx().shell().status_with_color(
change.kind.status(),
format!("{change}{note}"),
&change.kind.style(),
)?;
if let Some(note) = note {
if latest.is_some() {
unchanged_behind += 1;
}
if ws.gctx().shell().verbosity() == Verbosity::Verbose {
ws.gctx().shell().status_with_color(
change.kind.status(),
format!("{change}{note}"),
&change.kind.style(),
)?;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/global_cache_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ fn frequency() {
.env("CARGO_GC_AUTO_FREQUENCY", "1 day")
.masquerade_as_nightly_cargo(&["gc"])
.run();
assert_eq!(get_index_names().len(), 1);
assert_eq!(get_index_names().len(), 0);
assert_eq!(get_registry_names("src").len(), 0);
assert_eq!(get_registry_names("cache").len(), 0);
}
Expand Down Expand Up @@ -613,7 +613,7 @@ fn auto_gc_various_commands() {
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
let indexes = tracker.registry_index_all().unwrap();
assert_eq!(indexes.len(), 1);
assert_eq!(indexes.len(), 0);
let crates = tracker.registry_crate_all().unwrap();
assert_eq!(crates.len(), 0);
let srcs = tracker.registry_src_all().unwrap();
Expand Down

0 comments on commit bb1d830

Please sign in to comment.