summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--gitTag.byAge.go65
2 files changed, 58 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index f7434ed..6141989 100644
--- a/Makefile
+++ b/Makefile
@@ -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 \
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)
}