32 lines
583 B
Go
32 lines
583 B
Go
|
package gitpb
|
||
|
|
||
|
// runs git, parses output
|
||
|
// types faster than you can
|
||
|
|
||
|
import (
|
||
|
"sort"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func (all *GitTags) SortByAge() *GitTagIterator {
|
||
|
packs := all.selectAllGitTag()
|
||
|
|
||
|
sort.Sort(GitTagAge(packs))
|
||
|
|
||
|
iterator := NewGitTagIterator(packs)
|
||
|
return iterator
|
||
|
}
|
||
|
|
||
|
type GitTagAge []*GitTag
|
||
|
|
||
|
func (a GitTagAge) Len() int { return len(a) }
|
||
|
|
||
|
// sorts in ? order
|
||
|
func (a GitTagAge) Less(i, j int) bool {
|
||
|
if time.Since(a[i].Authordate.AsTime()) < time.Since(a[j].Authordate.AsTime()) {
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
func (a GitTagAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|