WIP: draft incomplete keep rule for keeping most recent common ancestor

This commit is contained in:
Christian Schwarz
2019-10-10 13:34:33 +02:00
parent 3edfe535c6
commit 3de3e2b688
5 changed files with 63 additions and 0 deletions
@@ -0,0 +1,29 @@
package pruning
import "sort"
type KeepMostRecentCommonAncestor struct {
_opaque struct{}
}
func NewKeepMostRecentCommonAncestor() *KeepMostRecentCommonAncestor {
return &KeepMostRecentCommonAncestor{}
}
func (k *KeepMostRecentCommonAncestor) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
var bothSides []Snapshot
for _, s := range snaps {
if s.PresentOnBothSides() {
bothSides = append(bothSides, s)
}
}
if len(bothSides) == 0 {
return []Snapshot{}
}
sort.Slice(bothSides, func(i, j int) bool {
return bothSides[i].Date().After(bothSides[j].Date())
})
return []Snapshot{bothSides[0]}
}