package gitpb import ( "path/filepath" "sort" "time" "go.wit.com/log" ) /* // todo: probably switch to using slices. new things added in 1.23 // https://pkg.go.dev/slices func (all *Stats) newSort() *StatScanner { slices.SortFunc(all.Stats, func(a, b *Stat) int { if n := strings.Compare(a.Name, b.Name); n != 0 { return n } // If names are equal, order by age return cmp.Compare(a.Age, b.Age) }) } */ // all this code below is junk and seamingly wrong func (all *Stats) GetAge(name string) time.Time { packs := all.selectAllStats() var newest time.Time for _, tag := range packs { // log.Info("\t\ttag", i, tag.Name, tag.AuthorTime.AsTime()) _, rname := filepath.Split(tag.Name) if name == rname { // log.Info("\t\tfound tag", i, rbase, rname, tag.AuthorTime.AsTime()) newest = tag.AuthorTime.AsTime() return newest } newest = tag.AuthorTime.AsTime() } return newest } func (all *Stats) SortByAge() *StatScanner { packs := all.selectAllStats() sort.Sort(StatAge(packs)) iterator := newStatScanner(packs) return iterator } type StatAge []*Stat func (a StatAge) Len() int { return len(a) } // sorts in ? order func (a StatAge) Less(i, j int) bool { if time.Since(a[i].AuthorTime.AsTime()) < time.Since(a[j].AuthorTime.AsTime()) { return true } return false } func (a StatAge) 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 { alltags := repo.Tags.selectAllStats() var newest time.Time for _, tag := range alltags { // check the actual age of the patch if newest.Before(tag.AuthorTime.AsTime()) { newest = tag.AuthorTime.AsTime() } // check the age of the commit if newest.Before(tag.CommitTime.AsTime()) { newest = tag.CommitTime.AsTime() } } return time.Since(newest) } func (repo *Repo) NewestTime() time.Time { alltags := repo.Tags.selectAllStats() var newest time.Time for _, tag := range alltags { // check the actual age of the patch if newest.Before(tag.AuthorTime.AsTime()) { newest = tag.AuthorTime.AsTime() } // check the age of the commit if newest.Before(tag.CommitTime.AsTime()) { newest = tag.CommitTime.AsTime() } } return newest } func (repo *Repo) NewestAgeVerbose() time.Duration { alltags := repo.Tags.selectAllStats() var newest time.Time var cur time.Time for i, tag := range alltags { cur = tag.AuthorTime.AsTime() rbase, rname := filepath.Split(tag.Name) log.Info("\t\tfound tag", i, rbase, rname, tag.AuthorTime.AsTime(), tag.CommitTime.AsTime()) if newest.Before(cur) { newest = cur } } return time.Since(newest) } // not really accurate. temprorary until git Config() parsing is better func (repo *Repo) BranchAge(branch string) time.Duration { alltags := repo.Tags.selectAllStats() var newest time.Time var cur time.Time var auth time.Time for _, tag := range alltags { cur = tag.CommitTime.AsTime() auth = tag.AuthorTime.AsTime() if branch == filepath.Base(tag.Name) { // log.Info("\t\tfound tag", i, branch, tag.AuthorTime.AsTime(), tag.CommitTime.AsTime()) if cur.Before(auth) { return time.Since(auth) } return time.Since(cur) } // check both dates I guess if newest.Before(auth) { newest = auth } if newest.Before(cur) { newest = cur } } return time.Since(newest) }