more accurate repo Age()

This commit is contained in:
Jeff Carr 2025-01-17 04:48:08 -06:00
parent 8c06b25fc2
commit bd925757df
2 changed files with 58 additions and 8 deletions

View File

@ -22,6 +22,7 @@ goimports:
clean:
rm -f *.pb.go
-rm -f go.*
go-mod-clean --purge
#refs.pb.go: refs.proto
# cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/lib/protobuf/gitpb \

View File

@ -1,8 +1,11 @@
package gitpb
import (
"path/filepath"
"sort"
"time"
"go.wit.com/log"
)
/*
@ -22,6 +25,25 @@ func (all *GitTags) newSort() *GitTagIterator {
// 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()
@ -44,14 +66,41 @@ func (a GitTagAge) Less(i, j int) bool {
}
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 {
return time.Since(repo.Times.NewestCommit.AsTime())
/*
all := repo.Tags.SortByAge()
for all.Scan() {
r := all.Next()
return time.Since(r.GetAuthordate().AsTime())
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()
}
return time.Since(time.Now())
*/
// 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)
}