mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-06 05:30:57 +00:00
snapshot: merge adjustments for -latest flag
This commit is contained in:
+20
-16
@@ -286,33 +286,37 @@ func (l *PackageRefList) Merge(r *PackageRefList, overrideMatching bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if newestWins {
|
if newestWins {
|
||||||
// A running tab of packages observed during a merge. Used when -newest
|
// A running tab of packages observed during a merge. Used when -latest
|
||||||
// is passed to ensure the newest version is carried into the snapshot.
|
// is passed to ensure the newest version is carried into the snapshot.
|
||||||
refs := make(map[string][]byte)
|
latestRefs := make(map[string][]byte)
|
||||||
|
|
||||||
OUTER:
|
|
||||||
for _, ref := range result.Refs {
|
for _, ref := range result.Refs {
|
||||||
partsL := bytes.Split(ref, []byte(" "))
|
partsL := bytes.Split(ref, []byte(" "))
|
||||||
nameL, archL, verL := partsL[0][1:], partsL[1], partsL[2]
|
archL, nameL, verL := partsL[0][1:], partsL[1], partsL[2]
|
||||||
pkgL := string(nameL) + "." + string(archL)
|
pkgId := string(nameL) + "." + string(archL)
|
||||||
|
|
||||||
|
// If the package hasn't been seen before, just add it.
|
||||||
|
if _, ok := latestRefs[pkgId]; !ok {
|
||||||
|
latestRefs[pkgId] = ref
|
||||||
|
il++
|
||||||
|
ir++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// If we've already seen this package, check if this version is
|
// If we've already seen this package, check if this version is
|
||||||
// newer. If it is, replace the older ref.
|
// newer. If it is, replace the older ref.
|
||||||
if _, ok := refs[pkgL]; ok {
|
partsR := bytes.Split(latestRefs[pkgId], []byte(" "))
|
||||||
vres := CompareVersions(string(verL), string(refs[pkgL]))
|
verR := partsR[2]
|
||||||
if vres <= 0 {
|
|
||||||
refs[pkgL] = ref
|
|
||||||
il++
|
|
||||||
ir++
|
|
||||||
continue OUTER
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
refs[pkgL] = ref
|
vres := CompareVersions(string(verL), string(verR))
|
||||||
|
if vres > 0 {
|
||||||
|
latestRefs[pkgId] = ref
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace the result with the merged copy of latest-only refs.
|
||||||
result.Refs = [][]byte{}
|
result.Refs = [][]byte{}
|
||||||
for _, ref := range refs {
|
for _, ref := range latestRefs {
|
||||||
result.Refs = append(result.Refs, ref)
|
result.Refs = append(result.Refs, ref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user