Sort PackagesList by name and version

This commit is contained in:
Simon Aquino
2014-06-13 11:42:20 +01:00
parent 856dd7021c
commit ff77fbf5d9
+9 -2
View File
@@ -300,9 +300,16 @@ func (l *PackageList) Swap(i, j int) {
l.packagesIndex[i], l.packagesIndex[j] = l.packagesIndex[j], l.packagesIndex[i]
}
// Compare compares two names in lexographical order
// Compare compares two packages by name in lexographical order and version
func (l *PackageList) Less(i, j int) bool {
return l.packagesIndex[i].Name < l.packagesIndex[j].Name
iPkg := l.packagesIndex[i]
jPkg := l.packagesIndex[j]
if iPkg.Name == jPkg.Name {
return CompareVersions(iPkg.Version, jPkg.Version) == -1
}
return iPkg.Name < jPkg.Name
}
// PrepareIndex prepares list for indexing