summaryrefslogtreecommitdiff
path: root/gitTag.byAge.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-17 04:48:08 -0600
committerJeff Carr <[email protected]>2025-01-17 04:48:08 -0600
commitbd925757dfc497eda01b9ccbf1d60fa88c75df99 (patch)
tree749c2d03f995dabe73aaaa88ae172ada0f9beb90 /gitTag.byAge.go
parent8c06b25fc271e0290fb0fe44eebc563ba62a6f67 (diff)
more accurate repo Age()v0.0.52
Diffstat (limited to 'gitTag.byAge.go')
-rw-r--r--gitTag.byAge.go65
1 files changed, 57 insertions, 8 deletions
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)
}