688 lines
16 KiB
Go
688 lines
16 KiB
Go
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
|
// This file was autogenerated with autogenpb v0.5.5-2-g6c9a3dd 2025.09.22_0851
|
|
// 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 forgepb
|
|
|
|
import (
|
|
"fmt"
|
|
"iter"
|
|
"sort"
|
|
"sync"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// a simple global lock
|
|
var patchsetMu sync.RWMutex
|
|
|
|
func (x *Patchsets) fixUuid() {
|
|
if x == nil {
|
|
return
|
|
}
|
|
if x.Uuid == "be926ad9-f07f-484c-adf2-d96eeabf3079" {
|
|
return
|
|
}
|
|
x.Uuid = "be926ad9-f07f-484c-adf2-d96eeabf3079"
|
|
x.Version = "v0.0.45 go.wit.com/lib/protobuf/forgepb"
|
|
}
|
|
|
|
func NewPatchsets() *Patchsets {
|
|
x := new(Patchsets)
|
|
x.Uuid = "be926ad9-f07f-484c-adf2-d96eeabf3079"
|
|
x.Version = "v0.0.45 go.wit.com/lib/protobuf/forgepb"
|
|
return x
|
|
}
|
|
|
|
// START SORT
|
|
|
|
// DEFINE THE Patchsets SCANNER.
|
|
// itializes a new scanner.
|
|
func newPatchsetsScanner(things []*Patchsets) *PatchsetsScanner {
|
|
return &PatchsetsScanner{things: things}
|
|
}
|
|
|
|
type PatchsetsScanner struct {
|
|
sync.Mutex
|
|
|
|
things []*Patchsets
|
|
index int
|
|
}
|
|
|
|
func (it *PatchsetsScanner) 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 *PatchsetsScanner) Next() *Patchsets {
|
|
if it.things[it.index-1] == nil {
|
|
fmt.Println("Next() error in PatchsetsScanner", it.index)
|
|
}
|
|
return it.things[it.index-1]
|
|
}
|
|
|
|
// END DEFINE THE SCANNER
|
|
|
|
// DEFINE THE Patchset SCANNER.
|
|
// itializes a new scanner.
|
|
func newPatchsetScanner(things []*Patchset) *PatchsetScanner {
|
|
return &PatchsetScanner{things: things}
|
|
}
|
|
|
|
type PatchsetScanner struct {
|
|
sync.Mutex
|
|
|
|
things []*Patchset
|
|
index int
|
|
}
|
|
|
|
func (it *PatchsetScanner) 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 *PatchsetScanner) Next() *Patchset {
|
|
if it.things[it.index-1] == nil {
|
|
fmt.Println("Next() error in PatchsetScanner", it.index)
|
|
}
|
|
return it.things[it.index-1]
|
|
}
|
|
|
|
// END DEFINE THE SCANNER
|
|
|
|
// DEFINE THE Patch SCANNER.
|
|
// itializes a new scanner.
|
|
func newPatchScanner(things []*Patch) *PatchScanner {
|
|
return &PatchScanner{things: things}
|
|
}
|
|
|
|
type PatchScanner struct {
|
|
sync.Mutex
|
|
|
|
things []*Patch
|
|
index int
|
|
}
|
|
|
|
func (it *PatchScanner) 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 *PatchScanner) Next() *Patch {
|
|
if it.things[it.index-1] == nil {
|
|
fmt.Println("Next() error in PatchScanner", it.index)
|
|
}
|
|
return it.things[it.index-1]
|
|
}
|
|
|
|
// END DEFINE THE SCANNER
|
|
|
|
// DEFINE THE Patches SCANNER.
|
|
// itializes a new scanner.
|
|
func newPatchesScanner(things []*Patches) *PatchesScanner {
|
|
return &PatchesScanner{things: things}
|
|
}
|
|
|
|
type PatchesScanner struct {
|
|
sync.Mutex
|
|
|
|
things []*Patches
|
|
index int
|
|
}
|
|
|
|
func (it *PatchesScanner) 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 *PatchesScanner) Next() *Patches {
|
|
if it.things[it.index-1] == nil {
|
|
fmt.Println("Next() error in PatchesScanner", it.index)
|
|
}
|
|
return it.things[it.index-1]
|
|
}
|
|
|
|
// END DEFINE THE SCANNER
|
|
|
|
// sort struct by Name
|
|
type sortPatchsetName []*Patchset
|
|
|
|
func (a sortPatchsetName) Len() int { return len(a) }
|
|
func (a sortPatchsetName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
|
func (a sortPatchsetName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
|
// sort struct by GitAuthorName
|
|
type sortPatchsetGitAuthorName []*Patchset
|
|
|
|
func (a sortPatchsetGitAuthorName) Len() int { return len(a) }
|
|
func (a sortPatchsetGitAuthorName) Less(i, j int) bool {
|
|
return a[i].GitAuthorName < a[j].GitAuthorName
|
|
}
|
|
func (a sortPatchsetGitAuthorName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
|
// sort struct by Uuid
|
|
type sortPatchsetUuid []*Patchset
|
|
|
|
func (a sortPatchsetUuid) Len() int { return len(a) }
|
|
func (a sortPatchsetUuid) Less(i, j int) bool { return a[i].Uuid < a[j].Uuid }
|
|
func (a sortPatchsetUuid) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
|
// sort struct by Filename
|
|
type sortPatchFilename []*Patch
|
|
|
|
func (a sortPatchFilename) Len() int { return len(a) }
|
|
func (a sortPatchFilename) Less(i, j int) bool { return a[i].Filename < a[j].Filename }
|
|
func (a sortPatchFilename) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
|
// sort struct by CommitHash
|
|
type sortPatchCommitHash []*Patch
|
|
|
|
func (a sortPatchCommitHash) Len() int { return len(a) }
|
|
func (a sortPatchCommitHash) Less(i, j int) bool { return a[i].CommitHash < a[j].CommitHash }
|
|
func (a sortPatchCommitHash) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
|
// safely returns a slice of pointers to the FRUIT protobufs
|
|
func (x *Patchsets) allPatchsets() []*Patchset {
|
|
patchsetMu.RLock()
|
|
defer patchsetMu.RUnlock()
|
|
|
|
// Create a new slice to hold pointers to each FRUIT
|
|
var tmp []*Patchset
|
|
tmp = make([]*Patchset, len(x.Patchsets))
|
|
for i, p := range x.Patchsets {
|
|
tmp[i] = p // Copy pointers for safe iteration
|
|
}
|
|
|
|
return tmp
|
|
}
|
|
|
|
// safely returns a slice of pointers to the FRUIT protobufs
|
|
func (x *Patches) allPatches() []*Patch {
|
|
x.RLock()
|
|
defer x.RUnlock()
|
|
|
|
// Create a new slice to hold pointers to each FRUIT
|
|
var tmp []*Patch
|
|
tmp = make([]*Patch, len(x.Patches))
|
|
for i, p := range x.Patches {
|
|
tmp[i] = p // Copy pointers for safe iteration
|
|
}
|
|
|
|
return tmp
|
|
}
|
|
|
|
// safely returns a slice of pointers to the Patchset protobufs
|
|
func (x *Patchsets) selectAllPatchsets() []*Patchset {
|
|
patchsetMu.RLock()
|
|
defer patchsetMu.RUnlock()
|
|
|
|
// Create a new slice to hold pointers to each Patchset
|
|
var tmp []*Patchset
|
|
tmp = make([]*Patchset, len(x.Patchsets))
|
|
for i, p := range x.Patchsets {
|
|
tmp[i] = p // Copy pointers for safe iteration
|
|
}
|
|
|
|
return tmp
|
|
}
|
|
|
|
// safely returns a slice of pointers to the Patch protobufs
|
|
func (x *Patches) selectAllPatches() []*Patch {
|
|
x.RLock()
|
|
defer x.RUnlock()
|
|
|
|
// Create a new slice to hold pointers to each Patch
|
|
var tmp []*Patch
|
|
tmp = make([]*Patch, len(x.Patches))
|
|
for i, p := range x.Patches {
|
|
tmp[i] = p // Copy pointers for safe iteration
|
|
}
|
|
|
|
return tmp
|
|
}
|
|
func (x *Patchsets) SortByName() *PatchsetScanner {
|
|
// copy the pointers as fast as possible.
|
|
things := x.selectAllPatchsets()
|
|
|
|
// todo: try slices.SortFunc() instead to see what happens
|
|
sort.Sort(sortPatchsetName(things))
|
|
// slices.SortFunc(things, func(a, b *Patchsets) bool {
|
|
// return a.Name < b.Name // Sort by ??. let the compiler work it out??
|
|
// })
|
|
return newPatchsetScanner(things)
|
|
}
|
|
|
|
// 'for x := range' syntax using the awesome golang 1.24 'iter'
|
|
func (x *Patchsets) IterByName() iter.Seq[*Patchset] {
|
|
items := x.selectAllPatchsets()
|
|
sort.Sort(sortPatchsetName(items))
|
|
// log.Println("Made Iter.Seq[] with length", len(items))
|
|
return func(yield func(*Patchset) bool) {
|
|
for _, v := range items {
|
|
if !yield(v) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func (x *Patchsets) SortByGitAuthorName() *PatchsetScanner {
|
|
// copy the pointers as fast as possible.
|
|
things := x.selectAllPatchsets()
|
|
|
|
// todo: try slices.SortFunc() instead to see what happens
|
|
sort.Sort(sortPatchsetGitAuthorName(things))
|
|
// slices.SortFunc(things, func(a, b *Patchsets) bool {
|
|
// return a.GitAuthorName < b.GitAuthorName // Sort by ??. let the compiler work it out??
|
|
// })
|
|
return newPatchsetScanner(things)
|
|
}
|
|
|
|
// 'for x := range' syntax using the awesome golang 1.24 'iter'
|
|
func (x *Patchsets) IterByGitAuthorName() iter.Seq[*Patchset] {
|
|
items := x.selectAllPatchsets()
|
|
sort.Sort(sortPatchsetGitAuthorName(items))
|
|
// log.Println("Made Iter.Seq[] with length", len(items))
|
|
return func(yield func(*Patchset) bool) {
|
|
for _, v := range items {
|
|
if !yield(v) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func (x *Patchsets) SortByUuid() *PatchsetScanner {
|
|
// copy the pointers as fast as possible.
|
|
things := x.selectAllPatchsets()
|
|
|
|
// todo: try slices.SortFunc() instead to see what happens
|
|
sort.Sort(sortPatchsetUuid(things))
|
|
// slices.SortFunc(things, func(a, b *Patchsets) bool {
|
|
// return a.Uuid < b.Uuid // Sort by ??. let the compiler work it out??
|
|
// })
|
|
return newPatchsetScanner(things)
|
|
}
|
|
|
|
// 'for x := range' syntax using the awesome golang 1.24 'iter'
|
|
func (x *Patchsets) IterByUuid() iter.Seq[*Patchset] {
|
|
items := x.selectAllPatchsets()
|
|
sort.Sort(sortPatchsetUuid(items))
|
|
// log.Println("Made Iter.Seq[] with length", len(items))
|
|
return func(yield func(*Patchset) bool) {
|
|
for _, v := range items {
|
|
if !yield(v) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func (x *Patches) SortByFilename() *PatchScanner {
|
|
// copy the pointers as fast as possible.
|
|
things := x.selectAllPatches()
|
|
|
|
// todo: try slices.SortFunc() instead to see what happens
|
|
sort.Sort(sortPatchFilename(things))
|
|
// slices.SortFunc(things, func(a, b *Patches) bool {
|
|
// return a.Filename < b.Filename // Sort by ??. let the compiler work it out??
|
|
// })
|
|
return newPatchScanner(things)
|
|
}
|
|
|
|
// 'for x := range' syntax using the awesome golang 1.24 'iter'
|
|
func (x *Patches) IterByFilename() iter.Seq[*Patch] {
|
|
items := x.selectAllPatches()
|
|
sort.Sort(sortPatchFilename(items))
|
|
// log.Println("Made Iter.Seq[] with length", len(items))
|
|
return func(yield func(*Patch) bool) {
|
|
for _, v := range items {
|
|
if !yield(v) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func (x *Patches) SortByCommitHash() *PatchScanner {
|
|
// copy the pointers as fast as possible.
|
|
things := x.selectAllPatches()
|
|
|
|
// todo: try slices.SortFunc() instead to see what happens
|
|
sort.Sort(sortPatchCommitHash(things))
|
|
// slices.SortFunc(things, func(a, b *Patches) bool {
|
|
// return a.CommitHash < b.CommitHash // Sort by ??. let the compiler work it out??
|
|
// })
|
|
return newPatchScanner(things)
|
|
}
|
|
|
|
// 'for x := range' syntax using the awesome golang 1.24 'iter'
|
|
func (x *Patches) IterByCommitHash() iter.Seq[*Patch] {
|
|
items := x.selectAllPatches()
|
|
sort.Sort(sortPatchCommitHash(items))
|
|
// log.Println("Made Iter.Seq[] with length", len(items))
|
|
return func(yield func(*Patch) bool) {
|
|
for _, v := range items {
|
|
if !yield(v) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// END SORT
|
|
|
|
func (x *Patchsets) Len() int {
|
|
patchsetMu.RLock()
|
|
defer patchsetMu.RUnlock()
|
|
|
|
return len(x.Patchsets)
|
|
}
|
|
|
|
// a Append() shortcut (that does Clone() with a mutex) notsure if it really works
|
|
func (x *Patchsets) Append(y *Patchset) *Patchset {
|
|
patchsetMu.Lock()
|
|
defer patchsetMu.Unlock()
|
|
|
|
z := proto.Clone(y).(*Patchset)
|
|
x.Patchsets = append(x.Patchsets, z)
|
|
|
|
return z
|
|
}
|
|
|
|
func (x *Patches) Len() int {
|
|
x.RLock()
|
|
defer x.RUnlock()
|
|
|
|
return len(x.Patches)
|
|
}
|
|
|
|
// a Append() shortcut (that does Clone() with a mutex) notsure if it really works
|
|
func (x *Patches) Append(y *Patch) *Patch {
|
|
x.Lock()
|
|
defer x.Unlock()
|
|
|
|
z := proto.Clone(y).(*Patch)
|
|
x.Patches = append(x.Patches, z)
|
|
|
|
return z
|
|
}
|
|
|
|
func (x *Patchsets) All() *PatchsetScanner {
|
|
PatchsetPointers := x.selectAllPatchsets()
|
|
|
|
scanner := newPatchsetScanner(PatchsetPointers)
|
|
return scanner
|
|
}
|
|
|
|
// Iterate 'for x := range' syntax using the awesome golang 1.24 'iter'
|
|
func (x *Patchsets) IterAll() iter.Seq[*Patchset] {
|
|
items := x.selectAllPatchsets()
|
|
// log.Println("Made All() Iter.Seq[] with length", len(items))
|
|
return func(yield func(*Patchset) bool) {
|
|
for _, v := range items {
|
|
if !yield(v) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func (x *Patches) All() *PatchScanner {
|
|
PatchPointers := x.selectAllPatches()
|
|
|
|
scanner := newPatchScanner(PatchPointers)
|
|
return scanner
|
|
}
|
|
|
|
// Iterate 'for x := range' syntax using the awesome golang 1.24 'iter'
|
|
func (x *Patches) IterAll() iter.Seq[*Patch] {
|
|
items := x.selectAllPatches()
|
|
// log.Println("Made All() Iter.Seq[] with length", len(items))
|
|
return func(yield func(*Patch) bool) {
|
|
for _, v := range items {
|
|
if !yield(v) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func (x *Patchsets) Delete(y *Patchset) bool {
|
|
patchsetMu.Lock()
|
|
defer patchsetMu.Unlock()
|
|
|
|
for i, _ := range x.Patchsets {
|
|
if x.Patchsets[i] == y {
|
|
x.Patchsets[i] = x.Patchsets[len(x.Patchsets)-1]
|
|
x.Patchsets = x.Patchsets[:len(x.Patchsets)-1]
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (x *Patches) Delete(y *Patch) bool {
|
|
x.Lock()
|
|
defer x.Unlock()
|
|
|
|
for i, _ := range x.Patches {
|
|
if x.Patches[i] == y {
|
|
x.Patches[i] = x.Patches[len(x.Patches)-1]
|
|
x.Patches = x.Patches[:len(x.Patches)-1]
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// lookup a Patchsets by the Uuid
|
|
func (x *Patchsets) FindByUuid(s string) *Patchset {
|
|
if x == nil {
|
|
return nil
|
|
}
|
|
|
|
patchsetMu.RLock()
|
|
defer patchsetMu.RUnlock()
|
|
|
|
for i, _ := range x.Patchsets {
|
|
if x.Patchsets[i].Uuid == s {
|
|
return x.Patchsets[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// returns a Patchset if Uuid matches, otherwise create
|
|
func (x *Patchsets) InsertByUuid(y string) *Patchset {
|
|
patchsetMu.Lock()
|
|
defer patchsetMu.Unlock()
|
|
|
|
for _, z := range x.Patchsets {
|
|
if z.Uuid == y {
|
|
return z
|
|
}
|
|
}
|
|
|
|
z := new(Patchset)
|
|
z.Uuid = y
|
|
x.Patchsets = append(x.Patchsets, z)
|
|
return z
|
|
}
|
|
|
|
func (x *Patchsets) DeleteByUuid(s string) bool {
|
|
patchsetMu.Lock()
|
|
defer patchsetMu.Unlock()
|
|
|
|
for i, _ := range x.Patchsets {
|
|
if x.Patchsets[i].Uuid == s {
|
|
x.Patchsets[i] = x.Patchsets[len(x.Patchsets)-1]
|
|
x.Patchsets = x.Patchsets[:len(x.Patchsets)-1]
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (x *Patchsets) AppendByUuid(y *Patchset) bool {
|
|
patchsetMu.Lock()
|
|
defer patchsetMu.Unlock()
|
|
|
|
for _, p := range x.Patchsets {
|
|
if p.Uuid == y.Uuid {
|
|
return false
|
|
}
|
|
}
|
|
|
|
x.Patchsets = append(x.Patchsets, proto.Clone(y).(*Patchset))
|
|
return true
|
|
}
|
|
|
|
// lookup a Patches by the Filename
|
|
func (x *Patches) FindByFilename(s string) *Patch {
|
|
if x == nil {
|
|
return nil
|
|
}
|
|
|
|
x.RLock()
|
|
defer x.RUnlock()
|
|
|
|
for i, _ := range x.Patches {
|
|
if x.Patches[i].Filename == s {
|
|
return x.Patches[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// returns a Patch if Filename matches, otherwise create
|
|
func (x *Patches) InsertByFilename(y string) *Patch {
|
|
x.Lock()
|
|
defer x.Unlock()
|
|
|
|
for _, z := range x.Patches {
|
|
if z.Filename == y {
|
|
return z
|
|
}
|
|
}
|
|
|
|
z := new(Patch)
|
|
z.Filename = y
|
|
x.Patches = append(x.Patches, z)
|
|
return z
|
|
}
|
|
|
|
// lookup a Patches by the CommitHash
|
|
func (x *Patches) FindByCommitHash(s string) *Patch {
|
|
if x == nil {
|
|
return nil
|
|
}
|
|
|
|
x.RLock()
|
|
defer x.RUnlock()
|
|
|
|
for i, _ := range x.Patches {
|
|
if x.Patches[i].CommitHash == s {
|
|
return x.Patches[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// returns a Patch if CommitHash matches, otherwise create
|
|
func (x *Patches) InsertByCommitHash(y string) *Patch {
|
|
x.Lock()
|
|
defer x.Unlock()
|
|
|
|
for _, z := range x.Patches {
|
|
if z.CommitHash == y {
|
|
return z
|
|
}
|
|
}
|
|
|
|
z := new(Patch)
|
|
z.CommitHash = y
|
|
x.Patches = append(x.Patches, z)
|
|
return z
|
|
}
|
|
|
|
func (x *Patches) DeleteByFilename(s string) bool {
|
|
x.Lock()
|
|
defer x.Unlock()
|
|
|
|
for i, _ := range x.Patches {
|
|
if x.Patches[i].Filename == s {
|
|
x.Patches[i] = x.Patches[len(x.Patches)-1]
|
|
x.Patches = x.Patches[:len(x.Patches)-1]
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (x *Patches) DeleteByCommitHash(s string) bool {
|
|
x.Lock()
|
|
defer x.Unlock()
|
|
|
|
for i, _ := range x.Patches {
|
|
if x.Patches[i].CommitHash == s {
|
|
x.Patches[i] = x.Patches[len(x.Patches)-1]
|
|
x.Patches = x.Patches[:len(x.Patches)-1]
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (x *Patches) AppendByFilename(y *Patch) bool {
|
|
x.Lock()
|
|
defer x.Unlock()
|
|
|
|
for _, p := range x.Patches {
|
|
if p.Filename == y.Filename {
|
|
return false
|
|
}
|
|
}
|
|
|
|
x.Patches = append(x.Patches, proto.Clone(y).(*Patch))
|
|
return true
|
|
}
|
|
|
|
func (x *Patches) AppendByCommitHash(y *Patch) bool {
|
|
x.Lock()
|
|
defer x.Unlock()
|
|
|
|
for _, p := range x.Patches {
|
|
if p.CommitHash == y.CommitHash {
|
|
return false
|
|
}
|
|
}
|
|
|
|
x.Patches = append(x.Patches, proto.Clone(y).(*Patch))
|
|
return true
|
|
}
|