more accurate repo Age()
This commit is contained in:
parent
8c06b25fc2
commit
bd925757df
1
Makefile
1
Makefile
|
@ -22,6 +22,7 @@ goimports:
|
||||||
clean:
|
clean:
|
||||||
rm -f *.pb.go
|
rm -f *.pb.go
|
||||||
-rm -f go.*
|
-rm -f go.*
|
||||||
|
go-mod-clean --purge
|
||||||
|
|
||||||
#refs.pb.go: refs.proto
|
#refs.pb.go: refs.proto
|
||||||
# cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/lib/protobuf/gitpb \
|
# cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/lib/protobuf/gitpb \
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package gitpb
|
package gitpb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -22,6 +25,25 @@ func (all *GitTags) newSort() *GitTagIterator {
|
||||||
|
|
||||||
// all this code below is junk and seamingly wrong
|
// 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 {
|
func (all *GitTags) SortByAge() *GitTagIterator {
|
||||||
packs := all.selectAllGitTags()
|
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] }
|
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 {
|
func (repo *Repo) NewestAge() time.Duration {
|
||||||
return time.Since(repo.Times.NewestCommit.AsTime())
|
alltags := repo.Tags.selectAllGitTags()
|
||||||
/*
|
|
||||||
all := repo.Tags.SortByAge()
|
var newest time.Time
|
||||||
for all.Scan() {
|
|
||||||
r := all.Next()
|
for _, tag := range alltags {
|
||||||
return time.Since(r.GetAuthordate().AsTime())
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue