mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Insert into right position when adding as well. #67
This commit is contained in:
+7
-6
@@ -101,7 +101,7 @@ func (l *PackageList) Add(p *Package) error {
|
||||
l.providesIndex[provides] = append(l.providesIndex[provides], p)
|
||||
}
|
||||
|
||||
i := sort.Search(len(l.packagesIndex), func(j int) bool { return l.packagesIndex[j].Name >= p.Name })
|
||||
i := sort.Search(len(l.packagesIndex), func(j int) bool { return l.lessPackages(p, l.packagesIndex[j]) })
|
||||
|
||||
// insert p into l.packagesIndex in position i
|
||||
l.packagesIndex = append(l.packagesIndex, nil)
|
||||
@@ -300,11 +300,7 @@ func (l *PackageList) Swap(i, j int) {
|
||||
l.packagesIndex[i], l.packagesIndex[j] = l.packagesIndex[j], l.packagesIndex[i]
|
||||
}
|
||||
|
||||
// Compare compares two packages by name (lexographical) and version (latest to oldest)
|
||||
func (l *PackageList) Less(i, j int) bool {
|
||||
iPkg := l.packagesIndex[i]
|
||||
jPkg := l.packagesIndex[j]
|
||||
|
||||
func (l *PackageList) lessPackages(iPkg, jPkg *Package) bool {
|
||||
if iPkg.Name == jPkg.Name {
|
||||
return CompareVersions(iPkg.Version, jPkg.Version) == 1
|
||||
}
|
||||
@@ -312,6 +308,11 @@ func (l *PackageList) Less(i, j int) bool {
|
||||
return iPkg.Name < jPkg.Name
|
||||
}
|
||||
|
||||
// Less compares two packages by name (lexographical) and version (latest to oldest)
|
||||
func (l *PackageList) Less(i, j int) bool {
|
||||
return l.lessPackages(l.packagesIndex[i], l.packagesIndex[j])
|
||||
}
|
||||
|
||||
// PrepareIndex prepares list for indexing
|
||||
func (l *PackageList) PrepareIndex() {
|
||||
l.packagesIndex = make([]*Package, l.Len())
|
||||
|
||||
Reference in New Issue
Block a user