2024-11-04 02:14:54 -06:00
|
|
|
package repolist
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2024-11-04 06:15:45 -06:00
|
|
|
"sort"
|
2024-11-04 02:14:54 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type RepoIterator struct {
|
|
|
|
repos []*RepoRow
|
|
|
|
index int
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRepoIterator initializes a new iterator.
|
|
|
|
func NewRepoIterator(repos []*RepoRow) *RepoIterator {
|
|
|
|
return &RepoIterator{repos: repos}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan moves to the next element and returns false if there are no more repos.
|
|
|
|
func (it *RepoIterator) Scan() bool {
|
|
|
|
if it.index >= len(it.repos) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
it.index++
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Repo returns the current repo.
|
|
|
|
func (it *RepoIterator) Repo() *RepoRow {
|
|
|
|
if it.repos[it.index-1] == nil {
|
|
|
|
for i, d := range it.repos {
|
|
|
|
fmt.Println("i =", i, d)
|
|
|
|
}
|
|
|
|
fmt.Println("len =", len(it.repos))
|
|
|
|
fmt.Println("repo == nil", it.index, it.index-1)
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
return it.repos[it.index-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use Scan() in a loop, similar to a while loop
|
|
|
|
//
|
|
|
|
// for iterator.Scan() {
|
|
|
|
// d := iterator.Repo()
|
|
|
|
// fmt.Println("Repo UUID:", d.Uuid)
|
|
|
|
// }
|
|
|
|
|
|
|
|
func (r *RepoList) ReposAll() *RepoIterator {
|
|
|
|
repoPointers := r.selectRepoAll()
|
|
|
|
|
|
|
|
iterator := NewRepoIterator(repoPointers)
|
|
|
|
|
|
|
|
return iterator
|
|
|
|
}
|
|
|
|
|
2024-11-04 06:15:45 -06:00
|
|
|
func (r *RepoList) ReposSortByName() *RepoIterator {
|
|
|
|
repoPointers := r.selectRepoAll()
|
|
|
|
|
|
|
|
sort.Sort(ByName(repoPointers))
|
|
|
|
|
|
|
|
iterator := NewRepoIterator(repoPointers)
|
|
|
|
|
|
|
|
return iterator
|
|
|
|
}
|
|
|
|
|
2024-11-05 01:02:00 -06:00
|
|
|
func (r *RepoList) UnmergedRepos() *RepoIterator {
|
2024-11-05 01:05:42 -06:00
|
|
|
repoPointers := r.selectUnmergedRepos()
|
2024-11-05 01:02:00 -06:00
|
|
|
|
|
|
|
sort.Sort(ByName(repoPointers))
|
|
|
|
|
|
|
|
iterator := NewRepoIterator(repoPointers)
|
|
|
|
|
|
|
|
return iterator
|
|
|
|
}
|
|
|
|
|
2024-11-04 06:15:45 -06:00
|
|
|
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] }
|
|
|
|
|
2024-11-04 02:14:54 -06:00
|
|
|
// SelectRepoPointers safely returns a slice of pointers to Repo records.
|
|
|
|
func (r *RepoList) selectRepoAll() []*RepoRow {
|
|
|
|
r.RLock()
|
|
|
|
defer r.RUnlock()
|
|
|
|
|
|
|
|
// Create a new slice to hold pointers to each Repo
|
|
|
|
// repoPointers := make([]*Repo, len(c.E.Repos))
|
|
|
|
var repoPointers []*RepoRow
|
|
|
|
for _, repo := range me.allrepos {
|
|
|
|
if repo == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if repo.Status == nil {
|
|
|
|
continue
|
|
|
|
}
|
2024-11-04 06:15:45 -06:00
|
|
|
if !repo.Status.InitOk {
|
2024-11-04 02:14:54 -06:00
|
|
|
continue
|
|
|
|
}
|
2024-11-05 05:58:33 -06:00
|
|
|
if repo.Status.Whitelist {
|
|
|
|
continue
|
|
|
|
}
|
2024-11-04 02:14:54 -06:00
|
|
|
repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration
|
|
|
|
}
|
|
|
|
|
|
|
|
return repoPointers
|
|
|
|
}
|
2024-11-05 01:02:00 -06:00
|
|
|
|
2024-11-08 06:43:45 -06:00
|
|
|
// this sort doesn't really work. I think it forgets to sort the last two
|
|
|
|
// todo: sort this out. literally
|
2024-11-05 01:02:00 -06:00
|
|
|
// SelectRepoPointers safely returns a slice of pointers to Repo records.
|
|
|
|
func (r *RepoList) selectUnmergedRepos() []*RepoRow {
|
|
|
|
r.RLock()
|
|
|
|
defer r.RUnlock()
|
|
|
|
|
|
|
|
// Create a new slice to hold pointers to each Repo
|
|
|
|
// repoPointers := make([]*Repo, len(c.E.Repos))
|
|
|
|
var repoPointers []*RepoRow
|
|
|
|
for _, repo := range me.allrepos {
|
|
|
|
if repo == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if repo.Status == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !repo.Status.InitOk {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if repo.ReadOnly() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if repo.State() == "PERFECT" {
|
|
|
|
continue
|
|
|
|
}
|
2024-11-05 03:14:27 -06:00
|
|
|
if repo.Status.Whitelist {
|
|
|
|
continue
|
|
|
|
}
|
2024-11-05 01:02:00 -06:00
|
|
|
if repo.Status.IsReleased() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration
|
|
|
|
}
|
|
|
|
|
|
|
|
return repoPointers
|
|
|
|
}
|