sort repos by name
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
98926bf2f8
commit
edfdb48ddf
17
common.go
17
common.go
|
@ -5,10 +5,8 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gui/shell"
|
||||
"go.wit.com/lib/gui/repostatus"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
@ -226,18 +224,3 @@ func (rl *RepoList) MakeGoWork() error {
|
|||
fmt.Fprintln(f, ")")
|
||||
return nil
|
||||
}
|
||||
|
||||
// makes a human readable thing for standard out.
|
||||
func (r *RepoRow) StandardHeader() string {
|
||||
lastTag := r.LastTag()
|
||||
tag := r.Status.NewestTag()
|
||||
gitAge, _ := tag.GetDate()
|
||||
dur := time.Since(gitAge)
|
||||
|
||||
master := r.Status.GetMasterVersion()
|
||||
devel := r.Status.GetDevelVersion()
|
||||
user := r.Status.GetUserVersion()
|
||||
|
||||
header := fmt.Sprintf("%-35s %5s %-10s %-10s %-10s %-10s %-15s", r.Name(), shell.FormatDuration(dur), lastTag, master, devel, user, r.State())
|
||||
return header
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package repolist
|
||||
|
||||
// make human readable output
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.wit.com/lib/gui/shell"
|
||||
)
|
||||
|
||||
// makes a human readable thing for standard out.
|
||||
func (r *RepoRow) StandardHeader() string {
|
||||
lastTag := r.LastTag()
|
||||
tag := r.Status.NewestTag()
|
||||
gitAge, _ := tag.GetDate()
|
||||
dur := time.Since(gitAge)
|
||||
|
||||
master := r.Status.GetMasterVersion()
|
||||
devel := r.Status.GetDevelVersion()
|
||||
user := r.Status.GetUserVersion()
|
||||
|
||||
header := fmt.Sprintf("%-35s %5s %-10s %-10s %-10s %-10s %-15s", r.Name(), shell.FormatDuration(dur), lastTag, master, devel, user, r.State())
|
||||
return header
|
||||
}
|
|
@ -3,6 +3,7 @@ package repolist
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type RepoIterator struct {
|
||||
|
@ -52,6 +53,22 @@ func (r *RepoList) ReposAll() *RepoIterator {
|
|||
return iterator
|
||||
}
|
||||
|
||||
func (r *RepoList) ReposSortByName() *RepoIterator {
|
||||
repoPointers := r.selectRepoAll()
|
||||
|
||||
sort.Sort(ByName(repoPointers))
|
||||
|
||||
iterator := NewRepoIterator(repoPointers)
|
||||
|
||||
return iterator
|
||||
}
|
||||
|
||||
type ByName []*RepoRow
|
||||
|
||||
func (a ByName) Len() int { return len(a) }
|
||||
func (a ByName) Less(i, j int) bool { return a[i].GoPath() < a[j].GoPath() }
|
||||
func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
// SelectRepoPointers safely returns a slice of pointers to Repo records.
|
||||
func (r *RepoList) selectRepoAll() []*RepoRow {
|
||||
r.RLock()
|
||||
|
|
Loading…
Reference in New Issue