Skip to content

Commit 388bb07

Browse files
committed
refactor(resolve): Allow lookups on changes by id
1 parent ef854d2 commit 388bb07

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/cargo/ops/cargo_update.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ fn print_lockfile_generation(
494494
) -> CargoResult<()> {
495495
let changes = PackageChange::new(ws, resolve);
496496
let num_pkgs: usize = changes
497-
.iter()
497+
.values()
498498
.filter(|change| change.kind.is_new() && !change.is_member.unwrap_or(false))
499499
.count();
500500
if num_pkgs == 0 {
@@ -503,7 +503,7 @@ fn print_lockfile_generation(
503503
}
504504
status_locking(ws, num_pkgs)?;
505505

506-
for change in changes {
506+
for change in changes.values() {
507507
if change.is_member.unwrap_or(false) {
508508
continue;
509509
};
@@ -555,7 +555,7 @@ fn print_lockfile_sync(
555555
) -> CargoResult<()> {
556556
let changes = PackageChange::diff(ws, previous_resolve, resolve);
557557
let num_pkgs: usize = changes
558-
.iter()
558+
.values()
559559
.filter(|change| change.kind.is_new() && !change.is_member.unwrap_or(false))
560560
.count();
561561
if num_pkgs == 0 {
@@ -564,7 +564,7 @@ fn print_lockfile_sync(
564564
}
565565
status_locking(ws, num_pkgs)?;
566566

567-
for change in changes {
567+
for change in changes.values() {
568568
if change.is_member.unwrap_or(false) {
569569
continue;
570570
};
@@ -611,13 +611,16 @@ fn print_lockfile_updates(
611611
registry: &mut PackageRegistry<'_>,
612612
) -> CargoResult<()> {
613613
let changes = PackageChange::diff(ws, previous_resolve, resolve);
614-
let num_pkgs: usize = changes.iter().filter(|change| change.kind.is_new()).count();
614+
let num_pkgs: usize = changes
615+
.values()
616+
.filter(|change| change.kind.is_new())
617+
.count();
615618
if !precise {
616619
status_locking(ws, num_pkgs)?;
617620
}
618621

619622
let mut unchanged_behind = 0;
620-
for change in changes {
623+
for change in changes.values() {
621624
let possibilities = if let Some(query) = change.alternatives_query() {
622625
loop {
623626
match registry.query_vec(&query, QueryKind::Exact) {
@@ -804,17 +807,24 @@ struct PackageChange {
804807
}
805808

806809
impl PackageChange {
807-
pub fn new(ws: &Workspace<'_>, resolve: &Resolve) -> Vec<Self> {
810+
pub fn new(ws: &Workspace<'_>, resolve: &Resolve) -> IndexMap<PackageId, Self> {
808811
let diff = PackageDiff::new(resolve);
809812
Self::with_diff(diff, ws)
810813
}
811814

812-
pub fn diff(ws: &Workspace<'_>, previous_resolve: &Resolve, resolve: &Resolve) -> Vec<Self> {
815+
pub fn diff(
816+
ws: &Workspace<'_>,
817+
previous_resolve: &Resolve,
818+
resolve: &Resolve,
819+
) -> IndexMap<PackageId, Self> {
813820
let diff = PackageDiff::diff(previous_resolve, resolve);
814821
Self::with_diff(diff, ws)
815822
}
816823

817-
fn with_diff(diff: impl Iterator<Item = PackageDiff>, ws: &Workspace<'_>) -> Vec<Self> {
824+
fn with_diff(
825+
diff: impl Iterator<Item = PackageDiff>,
826+
ws: &Workspace<'_>,
827+
) -> IndexMap<PackageId, Self> {
818828
let member_ids: HashSet<_> = ws.members().map(|p| p.package_id()).collect();
819829

820830
let mut changes = IndexMap::new();
@@ -876,7 +886,7 @@ impl PackageChange {
876886
}
877887
}
878888

879-
changes.into_values().collect()
889+
changes
880890
}
881891

882892
/// For querying [`PackageRegistry`] for alternative versions to report to the user

0 commit comments

Comments
 (0)