source-listing example sorts by version

This commit is contained in:
Chris West (Faux) 2017-07-20 12:59:21 +01:00
parent 77918dcee7
commit f8d5c5370b

View File

@ -36,32 +36,35 @@ fn main() {
let archive_filter = env::args().nth(1); let archive_filter = env::args().nth(1);
let mut cache = Cache::get_singleton(); let mut cache = Cache::get_singleton();
let mut all_packages = cache.iter();
let mut source_versions = HashMap::new(); let mut source_versions = HashMap::new();
while let Some(binary) = all_packages.next() { {
let mut all_packages = cache.iter();
let mut binary_versions = binary.versions(); while let Some(binary) = all_packages.next() {
while let Some(version) = binary_versions.next() { let mut binary_versions = binary.versions();
if let Some(ref target_archive) = archive_filter { while let Some(version) = binary_versions.next() {
if version if let Some(ref target_archive) = archive_filter {
.origin_iter() if version
.map(|origin| origin.file().next().unwrap().archive()) .origin_iter()
.any(|archive| archive == *target_archive) .map(|origin| origin.file().next().unwrap().archive())
{ .any(|archive| archive == *target_archive)
continue; {
continue;
}
} }
}
source_versions source_versions
.entry(version.source_package()) .entry(version.source_package())
.or_insert_with(HashSet::new) .or_insert_with(HashSet::new)
.insert(version.source_version()); .insert(version.source_version());
}
} }
} }
for src in lexicographic_sort(source_versions.keys()) { for src in lexicographic_sort(source_versions.keys()) {
for ver in lexicographic_sort(source_versions[src].iter()) { let mut sorted_versions: Vec<&String> = source_versions[src].iter().collect();
sorted_versions.sort_by(|left, right| cache.compare_versions(left, right));
for ver in sorted_versions {
println!("{}={}", src, ver); println!("{}={}", src, ver);
} }
} }