From 97cc9795818b2188d6bfa66f689f496d5f2df99c Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Sun, 28 Jan 2024 19:24:06 +0800 Subject: [PATCH 1/2] fix(cli): make pixi search result correct Signed-off-by: Chawye Hsu --- src/cli/search.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/cli/search.rs b/src/cli/search.rs index 36b714b97..fd53d83ac 100644 --- a/src/cli/search.rs +++ b/src/cli/search.rs @@ -53,30 +53,29 @@ where repo.package_names() .filter(|&name| filter_func(name, package)) }) + .unique() .collect::>(); let mut latest_packages = Vec::new(); // search for `similar_packages` in all platform's repodata // add the latest version of the fetched package to latest_packages vector - for repo in repo_data { - for package in &similar_packages { - let mut records = repo + for package in &similar_packages { + let mut records = Vec::new(); + + for repo in repo_data { + records.extend(repo .load_records(&PackageName::new_unchecked(*package)) - .into_diagnostic()?; - // sort records by version, get the latest one - records.sort_by(|a, b| a.package_record.version.cmp(&b.package_record.version)); - let latest_package = records.last().cloned(); - if let Some(latest_package) = latest_package { - latest_packages.push(latest_package); - } + .into_diagnostic()?); } - } - latest_packages = latest_packages - .into_iter() - .unique_by(|record| record.package_record.name.clone()) - .collect::>(); + // sort records by version, get the latest one + records.sort_by(|a, b| a.package_record.version.cmp(&b.package_record.version)); + let latest_package = records.last().cloned(); + if let Some(latest_package) = latest_package { + latest_packages.push(latest_package); + } + } Ok(latest_packages) } From c023fd39e0b73b0df0f27cbbdd2b65ed324845e9 Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Sun, 28 Jan 2024 19:30:00 +0800 Subject: [PATCH 2/2] cargo fmt Signed-off-by: Chawye Hsu --- src/cli/search.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cli/search.rs b/src/cli/search.rs index fd53d83ac..95fbb5541 100644 --- a/src/cli/search.rs +++ b/src/cli/search.rs @@ -64,9 +64,10 @@ where let mut records = Vec::new(); for repo in repo_data { - records.extend(repo - .load_records(&PackageName::new_unchecked(*package)) - .into_diagnostic()?); + records.extend( + repo.load_records(&PackageName::new_unchecked(*package)) + .into_diagnostic()?, + ); } // sort records by version, get the latest one