2024-12-06 01:50:28 -06:00
|
|
|
package gitpb
|
|
|
|
|
|
|
|
import (
|
2025-01-17 04:48:08 -06:00
|
|
|
"path/filepath"
|
2024-12-06 01:50:28 -06:00
|
|
|
"sort"
|
|
|
|
"time"
|
2025-01-17 04:48:08 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-12-06 01:50:28 -06:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
2025-01-17 04:48:08 -06:00
|
|
|
func (all *GitTags) GetAge(name string) time.Time {
|
|
|
|
packs := all.selectAllGitTags()
|
|
|
|
|
|
|
|
var newest time.Time
|
|
|
|
|
|
|
|
for _, tag := range packs {
|
|
|
|
// log.Info("\t\ttag", i, tag.Refname, tag.Authordate.AsTime())
|
|
|
|
_, rname := filepath.Split(tag.Refname)
|
|
|
|
if name == rname {
|
|
|
|
// log.Info("\t\tfound tag", i, rbase, rname, tag.Authordate.AsTime())
|
|
|
|
newest = tag.Authordate.AsTime()
|
|
|
|
return newest
|
|
|
|
}
|
|
|
|
newest = tag.Authordate.AsTime()
|
|
|
|
}
|
|
|
|
|
|
|
|
return newest
|
|
|
|
}
|
|
|
|
|
2024-12-06 01:50:28 -06:00
|
|
|
func (all *GitTags) SortByAge() *GitTagIterator {
|
2025-01-12 20:05:57 -06:00
|
|
|
packs := all.selectAllGitTags()
|
2024-12-06 01:50:28 -06:00
|
|
|
|
|
|
|
sort.Sort(GitTagAge(packs))
|
|
|
|
|
2025-01-12 20:05:57 -06:00
|
|
|
iterator := newGitTagIterator(packs)
|
2024-12-06 01:50:28 -06:00
|
|
|
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
|
|
|
|
2025-01-17 04:48:08 -06:00
|
|
|
// biased code that gives out newer tag dates
|
|
|
|
// even if the code hasn't been patched
|
2024-12-14 11:28:34 -06:00
|
|
|
func (repo *Repo) NewestAge() time.Duration {
|
2025-01-17 04:48:08 -06:00
|
|
|
alltags := repo.Tags.selectAllGitTags()
|
|
|
|
|
|
|
|
var newest time.Time
|
|
|
|
|
|
|
|
for _, tag := range alltags {
|
|
|
|
// check the actual age of the patch
|
|
|
|
if newest.Before(tag.Authordate.AsTime()) {
|
|
|
|
newest = tag.Authordate.AsTime()
|
2024-12-27 04:55:57 -06:00
|
|
|
}
|
2025-01-17 04:48:08 -06:00
|
|
|
// check the age of the commit
|
|
|
|
if newest.Before(tag.Creatordate.AsTime()) {
|
|
|
|
newest = tag.Creatordate.AsTime()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return time.Since(newest)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *Repo) NewestAgeVerbose() time.Duration {
|
|
|
|
alltags := repo.Tags.selectAllGitTags()
|
|
|
|
|
|
|
|
var newest time.Time
|
|
|
|
var cur time.Time
|
|
|
|
|
|
|
|
for i, tag := range alltags {
|
|
|
|
cur = tag.Authordate.AsTime()
|
|
|
|
rbase, rname := filepath.Split(tag.Refname)
|
|
|
|
log.Info("\t\tfound tag", i, rbase, rname, tag.Authordate.AsTime(), tag.Creatordate.AsTime())
|
|
|
|
if newest.Before(cur) {
|
|
|
|
newest = cur
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return time.Since(newest)
|
2024-12-14 11:28:34 -06:00
|
|
|
}
|
2025-01-19 10:49:08 -06:00
|
|
|
|
|
|
|
// not really accurate. temprorary until git Config() parsing is better
|
|
|
|
func (repo *Repo) BranchAge(branch string) time.Duration {
|
|
|
|
alltags := repo.Tags.selectAllGitTags()
|
|
|
|
|
|
|
|
var newest time.Time
|
|
|
|
var cur time.Time
|
|
|
|
var auth time.Time
|
|
|
|
|
|
|
|
for _, tag := range alltags {
|
|
|
|
cur = tag.Creatordate.AsTime()
|
|
|
|
auth = tag.Authordate.AsTime()
|
|
|
|
if branch == filepath.Base(tag.Refname) {
|
|
|
|
// log.Info("\t\tfound tag", i, branch, tag.Authordate.AsTime(), tag.Creatordate.AsTime())
|
|
|
|
if cur.Before(auth) {
|
|
|
|
return time.Since(auth)
|
|
|
|
}
|
|
|
|
return time.Since(cur)
|
|
|
|
}
|
|
|
|
|
|
|
|
// check both dates I guess
|
|
|
|
if newest.Before(auth) {
|
|
|
|
newest = auth
|
|
|
|
}
|
|
|
|
if newest.Before(cur) {
|
|
|
|
newest = cur
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return time.Since(newest)
|
|
|
|
}
|