From bd925757dfc497eda01b9ccbf1d60fa88c75df99 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 17 Jan 2025 04:48:08 -0600 Subject: more accurate repo Age() --- gitTag.byAge.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 8 deletions(-) (limited to 'gitTag.byAge.go') diff --git a/gitTag.byAge.go b/gitTag.byAge.go index 2b68b98..0033c45 100644 --- a/gitTag.byAge.go +++ b/gitTag.byAge.go @@ -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) } -- cgit v1.2.3