// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. // This file was autogenerated with autogenpb v0.5.3-11-g737c5b7 2025.09.16_2337 // go install go.wit.com/apps/autogenpb@latest // // define which structs (messages) you want to use in the .proto file // Then sort.pb.go and marshal.pb.go files are autogenerated // // autogenpb uses it and has an example .proto file with instructions // package gitpb import ( "fmt" "iter" "sort" "sync" "google.golang.org/protobuf/proto" ) // a simple global lock var repoMu sync.RWMutex func (x *Repos) fixUuid() { if x == nil { return } if x.Uuid == "8daaeba1-fb1f-4762-ae6e-95a55d352673" { return } x.Uuid = "8daaeba1-fb1f-4762-ae6e-95a55d352673" x.Version = "v4 go.wit.com/lib/protobuf/gitpb" } func NewRepos() *Repos { x := new(Repos) x.Uuid = "8daaeba1-fb1f-4762-ae6e-95a55d352673" x.Version = "v4 go.wit.com/lib/protobuf/gitpb" return x } // START SORT // DEFINE THE Repos SCANNER. // itializes a new scanner. func newReposScanner(things []*Repos) *ReposScanner { return &ReposScanner{things: things} } type ReposScanner struct { sync.Mutex things []*Repos index int } func (it *ReposScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ReposScanner) Next() *Repos { if it.things[it.index-1] == nil { fmt.Println("Next() error in ReposScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Repo SCANNER. // itializes a new scanner. func newRepoScanner(things []*Repo) *RepoScanner { return &RepoScanner{things: things} } type RepoScanner struct { sync.Mutex things []*Repo index int } func (it *RepoScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *RepoScanner) Next() *Repo { if it.things[it.index-1] == nil { fmt.Println("Next() error in RepoScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE GitTimes SCANNER. // itializes a new scanner. func newGitTimesScanner(things []*GitTimes) *GitTimesScanner { return &GitTimesScanner{things: things} } type GitTimesScanner struct { sync.Mutex things []*GitTimes index int } func (it *GitTimesScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *GitTimesScanner) Next() *GitTimes { if it.things[it.index-1] == nil { fmt.Println("Next() error in GitTimesScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE GoInfo SCANNER. // itializes a new scanner. func newGoInfoScanner(things []*GoInfo) *GoInfoScanner { return &GoInfoScanner{things: things} } type GoInfoScanner struct { sync.Mutex things []*GoInfo index int } func (it *GoInfoScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *GoInfoScanner) Next() *GoInfo { if it.things[it.index-1] == nil { fmt.Println("Next() error in GoInfoScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // sort struct by Namespace type sortRepoNamespace []*Repo func (a sortRepoNamespace) Len() int { return len(a) } func (a sortRepoNamespace) Less(i, j int) bool { return a[i].Namespace < a[j].Namespace } func (a sortRepoNamespace) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // sort struct by FullPath type sortRepoFullPath []*Repo func (a sortRepoFullPath) Len() int { return len(a) } func (a sortRepoFullPath) Less(i, j int) bool { return a[i].FullPath < a[j].FullPath } func (a sortRepoFullPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // safely returns a slice of pointers to the FRUIT protobufs func (x *Repos) allRepos() []*Repo { repoMu.RLock() defer repoMu.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Repo tmp = make([]*Repo, len(x.Repos)) for i, p := range x.Repos { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Repo protobufs func (x *Repos) selectAllRepos() []*Repo { repoMu.RLock() defer repoMu.RUnlock() // Create a new slice to hold pointers to each Repo var tmp []*Repo tmp = make([]*Repo, len(x.Repos)) for i, p := range x.Repos { tmp[i] = p // Copy pointers for safe iteration } return tmp } func (x *Repos) SortByNamespace() *RepoScanner { // copy the pointers as fast as possible. things := x.selectAllRepos() // todo: try slices.SortFunc() instead to see what happens sort.Sort(sortRepoNamespace(things)) // slices.SortFunc(things, func(a, b *Repos) bool { // return a.Namespace < b.Namespace // Sort by ??. let the compiler work it out?? // }) return newRepoScanner(things) } // 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *Repos) IterByNamespace() iter.Seq[*Repo] { items := x.selectAllRepos() sort.Sort(sortRepoNamespace(items)) // log.Println("Made Iter.Seq[] with length", len(items)) return func(yield func(*Repo) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *Repos) SortByFullPath() *RepoScanner { // copy the pointers as fast as possible. things := x.selectAllRepos() // todo: try slices.SortFunc() instead to see what happens sort.Sort(sortRepoFullPath(things)) // slices.SortFunc(things, func(a, b *Repos) bool { // return a.FullPath < b.FullPath // Sort by ??. let the compiler work it out?? // }) return newRepoScanner(things) } // 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *Repos) IterByFullPath() iter.Seq[*Repo] { items := x.selectAllRepos() sort.Sort(sortRepoFullPath(items)) // log.Println("Made Iter.Seq[] with length", len(items)) return func(yield func(*Repo) bool) { for _, v := range items { if !yield(v) { return } } } } // END SORT func (x *Repos) Len() int { repoMu.RLock() defer repoMu.RUnlock() return len(x.Repos) } // a Append() shortcut (that does Clone() with a mutex) notsure if it really works func (x *Repos) Append(y *Repo) *Repo { repoMu.Lock() defer repoMu.Unlock() z := proto.Clone(y).(*Repo) x.Repos = append(x.Repos, z) return z } func (x *Repos) All() *RepoScanner { RepoPointers := x.selectAllRepos() scanner := newRepoScanner(RepoPointers) return scanner } // Iterate 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *Repos) IterAll() iter.Seq[*Repo] { items := x.selectAllRepos() // log.Println("Made All() Iter.Seq[] with length", len(items)) return func(yield func(*Repo) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *Repos) Delete(y *Repo) bool { repoMu.Lock() defer repoMu.Unlock() for i, _ := range x.Repos { if x.Repos[i] == y { x.Repos[i] = x.Repos[len(x.Repos)-1] x.Repos = x.Repos[:len(x.Repos)-1] return true } } return false } // lookup a Repos by the Namespace func (x *Repos) FindByNamespace(s string) *Repo { if x == nil { return nil } repoMu.RLock() defer repoMu.RUnlock() for i, _ := range x.Repos { if x.Repos[i].Namespace == s { return x.Repos[i] } } return nil } // returns a Repo if Namespace matches, otherwise create func (x *Repos) InsertByNamespace(y string) *Repo { repoMu.Lock() defer repoMu.Unlock() for _, z := range x.Repos { if z.Namespace == y { return z } } z := new(Repo) z.Namespace = y x.Repos = append(x.Repos, z) return z } // lookup a Repos by the FullPath func (x *Repos) FindByFullPath(s string) *Repo { if x == nil { return nil } repoMu.RLock() defer repoMu.RUnlock() for i, _ := range x.Repos { if x.Repos[i].FullPath == s { return x.Repos[i] } } return nil } // returns a Repo if FullPath matches, otherwise create func (x *Repos) InsertByFullPath(y string) *Repo { repoMu.Lock() defer repoMu.Unlock() for _, z := range x.Repos { if z.FullPath == y { return z } } z := new(Repo) z.FullPath = y x.Repos = append(x.Repos, z) return z } func (x *Repos) DeleteByNamespace(s string) bool { repoMu.Lock() defer repoMu.Unlock() for i, _ := range x.Repos { if x.Repos[i].Namespace == s { x.Repos[i] = x.Repos[len(x.Repos)-1] x.Repos = x.Repos[:len(x.Repos)-1] return true } } return false } func (x *Repos) DeleteByFullPath(s string) bool { repoMu.Lock() defer repoMu.Unlock() for i, _ := range x.Repos { if x.Repos[i].FullPath == s { x.Repos[i] = x.Repos[len(x.Repos)-1] x.Repos = x.Repos[:len(x.Repos)-1] return true } } return false } func (x *Repos) AppendByNamespace(y *Repo) bool { repoMu.Lock() defer repoMu.Unlock() for _, p := range x.Repos { if p.Namespace == y.Namespace { return false } } x.Repos = append(x.Repos, proto.Clone(y).(*Repo)) return true } func (x *Repos) AppendByFullPath(y *Repo) bool { repoMu.Lock() defer repoMu.Unlock() for _, p := range x.Repos { if p.FullPath == y.FullPath { return false } } x.Repos = append(x.Repos, proto.Clone(y).(*Repo)) return true }