mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-16 12:08:04 +00:00
snapshot: simplify merging latest packages
This commit is contained in:
+13
-20
@@ -290,39 +290,32 @@ func (l *PackageRefList) Merge(r *PackageRefList, overrideMatching bool,
|
|||||||
// package reference is kept.
|
// package reference is kept.
|
||||||
latestRefs := make(map[string]int)
|
latestRefs := make(map[string]int)
|
||||||
|
|
||||||
for i, ref := range result.Refs {
|
i := 0
|
||||||
partsL := bytes.Split(ref, []byte(" "))
|
for _ = range result.Refs {
|
||||||
|
partsL := bytes.Split(result.Refs[i], []byte(" "))
|
||||||
archL, nameL, verL := partsL[0][1:], partsL[1], partsL[2]
|
archL, nameL, verL := partsL[0][1:], partsL[1], partsL[2]
|
||||||
pkgId := string(nameL) + "." + string(archL)
|
pkgId := string(nameL) + "." + string(archL)
|
||||||
|
|
||||||
// If the package hasn't been seen before, just add it.
|
// If the package hasn't been seen before, add it and advance.
|
||||||
if _, ok := latestRefs[pkgId]; !ok {
|
if _, ok := latestRefs[pkgId]; !ok {
|
||||||
latestRefs[pkgId] = i
|
latestRefs[pkgId] = i
|
||||||
|
i++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've already seen this package, check if this version is
|
// If we've already seen this package, check versions
|
||||||
// newer. If it is, replace the older ref.
|
|
||||||
partsR := bytes.Split(result.Refs[latestRefs[pkgId]], []byte(" "))
|
partsR := bytes.Split(result.Refs[latestRefs[pkgId]], []byte(" "))
|
||||||
verR := partsR[2]
|
verR := partsR[2]
|
||||||
|
|
||||||
vres := CompareVersions(string(verL), string(verR))
|
vres := CompareVersions(string(verL), string(verR))
|
||||||
if vres > 0 {
|
|
||||||
latestRefs[pkgId] = i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
offset := 0
|
// Remove the older or duplicate refs from the result
|
||||||
OUTER:
|
if vres <= 0 {
|
||||||
for i, _ := range result.Refs {
|
result.Refs = append(result.Refs[0:i], result.Refs[i+1:]...)
|
||||||
for _, ki := range latestRefs {
|
latestRefs[pkgId] = i
|
||||||
if ki == i {
|
} else {
|
||||||
continue OUTER
|
oi := latestRefs[pkgId]
|
||||||
}
|
result.Refs = append(result.Refs[0:oi], result.Refs[oi+1:]...)
|
||||||
}
|
}
|
||||||
idx := i - offset
|
|
||||||
result.Refs = append(result.Refs[0:idx], result.Refs[idx+1:]...)
|
|
||||||
offset++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user