diff options
| author | Jeff Carr <[email protected]> | 2024-11-04 06:15:45 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-04 06:15:45 -0600 |
| commit | edfdb48ddf85eb414a1a264f724a30eb8bef91d3 (patch) | |
| tree | ebbe376c19cf260a242cd247c5701a924f2ee969 /scanIterator.go | |
| parent | 98926bf2f80a25e51429d74182254da1103bdbc7 (diff) | |
sort repos by name
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'scanIterator.go')
| -rw-r--r-- | scanIterator.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/scanIterator.go b/scanIterator.go index 4214014..7f347b2 100644 --- a/scanIterator.go +++ b/scanIterator.go @@ -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() @@ -67,7 +84,7 @@ func (r *RepoList) selectRepoAll() []*RepoRow { if repo.Status == nil { continue } - if ! repo.Status.InitOk { + if !repo.Status.InitOk { continue } repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration |
