1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
package gitpb
import (
"path/filepath"
"sort"
"time"
"go.wit.com/log"
)
/*
// 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
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
}
func (all *GitTags) SortByAge() *GitTagIterator {
packs := all.selectAllGitTags()
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] }
// biased code that gives out newer tag dates
// even if the code hasn't been patched
func (repo *Repo) NewestAge() time.Duration {
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()
}
// 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)
}
|