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"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/gui/shell"
|
|
||||||
"go.wit.com/lib/gui/repostatus"
|
"go.wit.com/lib/gui/repostatus"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
@ -226,18 +224,3 @@ func (rl *RepoList) MakeGoWork() error {
|
||||||
fmt.Fprintln(f, ")")
|
fmt.Fprintln(f, ")")
|
||||||
return nil
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RepoIterator struct {
|
type RepoIterator struct {
|
||||||
|
@ -52,6 +53,22 @@ func (r *RepoList) ReposAll() *RepoIterator {
|
||||||
return iterator
|
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.
|
// SelectRepoPointers safely returns a slice of pointers to Repo records.
|
||||||
func (r *RepoList) selectRepoAll() []*RepoRow {
|
func (r *RepoList) selectRepoAll() []*RepoRow {
|
||||||
r.RLock()
|
r.RLock()
|
||||||
|
@ -67,7 +84,7 @@ func (r *RepoList) selectRepoAll() []*RepoRow {
|
||||||
if repo.Status == nil {
|
if repo.Status == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ! repo.Status.InitOk {
|
if !repo.Status.InitOk {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration
|
repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration
|
||||||
|
|
Loading…
Reference in New Issue