add NewestTag() and Tag.Age()
This commit is contained in:
parent
5aaf02ee3a
commit
cd5f1d9d0f
16
git.go
16
git.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"os/user"
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -19,6 +20,21 @@ func (rs *RepoStatus) GetCurrentBranchVersion() string {
|
||||||
return rs.currentVersion.String()
|
return rs.currentVersion.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rs *RepoStatus) Age() time.Duration {
|
||||||
|
var t *Tag
|
||||||
|
t = rs.NewestTag()
|
||||||
|
|
||||||
|
if t != nil {
|
||||||
|
log.Log(REPO, "newest tag:", t.date.String(), t.tag.String(), t.Name())
|
||||||
|
return t.Age()
|
||||||
|
}
|
||||||
|
|
||||||
|
const gitLayout = "Mon Jan 2 15:04:05 2006 -0700"
|
||||||
|
const madeuptime = "Mon Jun 3 15:04:05 2013 -0700"
|
||||||
|
tagTime, _ := time.Parse(gitLayout, madeuptime)
|
||||||
|
return time.Since(tagTime)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// this isn't right
|
// this isn't right
|
||||||
func (rs *RepoStatus) LastTagAge() (time.Time, string) {
|
func (rs *RepoStatus) LastTagAge() (time.Time, string) {
|
||||||
|
|
|
@ -136,6 +136,9 @@ func (rs *RepoStatus) readGitConfig() error {
|
||||||
switch currentSection {
|
switch currentSection {
|
||||||
case "core":
|
case "core":
|
||||||
rs.gitConfig.core[key] = value
|
rs.gitConfig.core[key] = value
|
||||||
|
case "pull":
|
||||||
|
// don't store git config pull settings here
|
||||||
|
// probably has 'rebase = false'
|
||||||
case "remote":
|
case "remote":
|
||||||
test, ok := rs.gitConfig.remotes[currentName]
|
test, ok := rs.gitConfig.remotes[currentName]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
8
new.go
8
new.go
|
@ -32,6 +32,14 @@ func FindPathOld(path string) *RepoStatus {
|
||||||
return windowMap[path]
|
return windowMap[path]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// makes a window of the status of the repo
|
||||||
|
// don't worry, you can think of it like Sierpinski carpet
|
||||||
|
// it's doesn't need to be displayed so it'll work fine even in an embedded space
|
||||||
|
func New(path string) (*RepoStatus, error) {
|
||||||
|
err, r := NewRepoStatusWindow(path)
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewRepoStatusWindow(path string) (error, *RepoStatus) {
|
func NewRepoStatusWindow(path string) (error, *RepoStatus) {
|
||||||
var realpath string
|
var realpath string
|
||||||
var isGoLang bool = false
|
var isGoLang bool = false
|
||||||
|
|
58
tagWindow.go
58
tagWindow.go
|
@ -5,6 +5,8 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -312,3 +314,59 @@ func (rs *RepoStatus) LocalTagExists(findname string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tag) Age() time.Duration {
|
||||||
|
const gitLayout = "Mon Jan 2 15:04:05 2006 -0700"
|
||||||
|
tagTime, _ := time.Parse(gitLayout, t.date.String())
|
||||||
|
return time.Since(tagTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tag) Name() string {
|
||||||
|
return t.tag.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tag) getDate() (time.Time, error) {
|
||||||
|
const gitLayout = "Mon Jan 2 15:04:05 2006 -0700"
|
||||||
|
tagTime, err := time.Parse(gitLayout, t.date.String())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Log(REPOWARN, "tag date err", t.ref.String(), t.tag.String(), err)
|
||||||
|
return time.Now(), err
|
||||||
|
}
|
||||||
|
return tagTime, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rs *RepoStatus) NewestTag() *Tag {
|
||||||
|
var newest *Tag
|
||||||
|
var newestTime time.Time
|
||||||
|
var tagTime time.Time
|
||||||
|
var err error
|
||||||
|
var allTags []*Tag
|
||||||
|
var mu sync.Mutex
|
||||||
|
|
||||||
|
allTags = make([]*Tag, 0, 0)
|
||||||
|
junk := rs.Tags.ListAll()
|
||||||
|
allTags = append(allTags, junk...)
|
||||||
|
for _, t := range allTags {
|
||||||
|
mu.Lock()
|
||||||
|
if tagTime, err = t.getDate(); err != nil {
|
||||||
|
mu.Unlock()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// log.Log(REPOWARN, "tag", t.ref.String(), t.date.String(), t.tag.String())
|
||||||
|
// if this is the first tag, use it
|
||||||
|
if newest == nil {
|
||||||
|
newestTime = tagTime
|
||||||
|
newest = t
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the tag date is after the newest date, it's newer so use this tag
|
||||||
|
if tagTime.After(newestTime) {
|
||||||
|
newestTime = tagTime
|
||||||
|
newest = t
|
||||||
|
}
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
|
return newest
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue