2024-12-06 01:50:28 -06:00
|
|
|
package gitpb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2024-12-27 14:40:27 -06:00
|
|
|
/*
|
|
|
|
// todo: probably switch to using slices. new things added in 1.23
|
|
|
|
// https://pkg.go.dev/slices
|
|
|
|
|
|
|
|
func (all *GitTags) newSort() *GitTagIterator {
|
|
|
|
slices.SortFunc(all.GitTags, func(a, b *GitTag) int {
|
|
|
|
if n := strings.Compare(a.Name, b.Name); n != 0 {
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
// If names are equal, order by age
|
|
|
|
return cmp.Compare(a.Age, b.Age)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// all this code below is junk and seamingly wrong
|
|
|
|
|
2024-12-06 01:50:28 -06:00
|
|
|
func (all *GitTags) SortByAge() *GitTagIterator {
|
|
|
|
packs := all.selectAllGitTag()
|
|
|
|
|
|
|
|
sort.Sort(GitTagAge(packs))
|
|
|
|
|
|
|
|
iterator := NewGitTagIterator(packs)
|
|
|
|
return iterator
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitTagAge []*GitTag
|
|
|
|
|
|
|
|
func (a GitTagAge) Len() int { return len(a) }
|
|
|
|
|
|
|
|
// sorts in ? order
|
|
|
|
func (a GitTagAge) Less(i, j int) bool {
|
|
|
|
if time.Since(a[i].Authordate.AsTime()) < time.Since(a[j].Authordate.AsTime()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
func (a GitTagAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
2024-12-14 11:28:34 -06:00
|
|
|
|
|
|
|
func (repo *Repo) NewestAge() time.Duration {
|
2024-12-27 04:55:57 -06:00
|
|
|
return time.Since(repo.Times.NewestCommit.AsTime())
|
|
|
|
/*
|
|
|
|
all := repo.Tags.SortByAge()
|
|
|
|
for all.Scan() {
|
|
|
|
r := all.Next()
|
|
|
|
return time.Since(r.GetAuthordate().AsTime())
|
|
|
|
}
|
|
|
|
return time.Since(time.Now())
|
|
|
|
*/
|
2024-12-14 11:28:34 -06:00
|
|
|
}
|