mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-05 05:20:34 +00:00
snapshot: Move 'newest' logic out of main compilation loop and evaluate the reflist afterward.
This commit is contained in:
+32
-33
@@ -226,10 +226,6 @@ func (l *PackageRefList) Diff(r *PackageRefList, packageCollection *PackageColle
|
||||
func (l *PackageRefList) Merge(r *PackageRefList, overrideMatching bool,
|
||||
newestWins bool) (result *PackageRefList) {
|
||||
|
||||
// A running tab of packages observed during a merge. Used when -newest is
|
||||
// passed to make sure only the newest version is carried into the snapshot.
|
||||
var seen []string
|
||||
|
||||
// pointer to left and right reflists
|
||||
il, ir := 0, 0
|
||||
// length of reflists
|
||||
@@ -238,7 +234,6 @@ func (l *PackageRefList) Merge(r *PackageRefList, overrideMatching bool,
|
||||
result = &PackageRefList{}
|
||||
result.Refs = make([][]byte, 0, ll+lr)
|
||||
|
||||
OUTER:
|
||||
// until we reached end of both lists
|
||||
for il < ll || ir < lr {
|
||||
// if we've exhausted left list, pull the rest from the right
|
||||
@@ -278,34 +273,6 @@ OUTER:
|
||||
continue
|
||||
}
|
||||
}
|
||||
if newestWins {
|
||||
partsL := bytes.Split(rl, []byte(" "))
|
||||
nameL, archL, verL := partsL[0][1:], partsL[1], partsL[2]
|
||||
pkgL := string(nameL) + "." + string(archL)
|
||||
|
||||
partsR := bytes.Split(rr, []byte(" "))
|
||||
verR := partsR[2]
|
||||
|
||||
// If we've already seen this package, regardless of version,
|
||||
// just skip it.
|
||||
for _, s := range seen {
|
||||
if s == pkgL {
|
||||
il++
|
||||
ir++
|
||||
continue OUTER
|
||||
}
|
||||
}
|
||||
|
||||
seen = append(seen, pkgL)
|
||||
|
||||
vres := CompareVersions(string(verL), string(verR))
|
||||
if vres <= 0 {
|
||||
result.Refs = append(result.Refs, r.Refs[ir])
|
||||
il++
|
||||
ir++
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise append smallest of two
|
||||
if rel < 0 {
|
||||
@@ -318,5 +285,37 @@ OUTER:
|
||||
}
|
||||
}
|
||||
|
||||
if newestWins {
|
||||
// A running tab of packages observed during a merge. Used when -newest
|
||||
// is passed to ensure the newest version is carried into the snapshot.
|
||||
refs := make(map[string][]byte)
|
||||
|
||||
OUTER:
|
||||
for _, ref := range result.Refs {
|
||||
partsL := bytes.Split(ref, []byte(" "))
|
||||
nameL, archL, verL := partsL[0][1:], partsL[1], partsL[2]
|
||||
pkgL := string(nameL) + "." + string(archL)
|
||||
|
||||
// If we've already seen this package, regardless of version,
|
||||
// just skip it.
|
||||
if _, ok := refs[pkgL]; ok {
|
||||
vres := CompareVersions(string(verL), string(refs[pkgL]))
|
||||
if vres <= 0 {
|
||||
refs[pkgL] = ref
|
||||
il++
|
||||
ir++
|
||||
continue OUTER
|
||||
}
|
||||
}
|
||||
|
||||
refs[pkgL] = ref
|
||||
}
|
||||
|
||||
result.Refs = [][]byte{}
|
||||
for _, ref := range refs {
|
||||
result.Refs = append(result.Refs, ref)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user