Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): make pixi search result correct #713

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/cli/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,30 @@ where
repo.package_names()
.filter(|&name| filter_func(name, package))
})
.unique()
.collect::<Vec<&str>>();

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
.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);
}
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()?,
);
}
}

latest_packages = latest_packages
.into_iter()
.unique_by(|record| record.package_record.name.clone())
.collect::<Vec<_>>();
// 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)
}
Expand Down
Loading