Notes added by 'git notes append'

This commit is contained in:
Jeff Carr 2025-01-11 06:17:21 -06:00
parent 75e71109bb
commit f91a91fe94
1 changed files with 113 additions and 0 deletions

View File

@ -1312,3 +1312,116 @@ func file_patchset_proto_init() {
}
// `autogen:patchset.sort.pb.go`
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.40-19-gfed674d 2025.01.11_0448
// 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"
"sort"
"sync"
)
type PatchsetIterator struct {
sync.RWMutex
things []*Patchset
index int
}
// NewPatchsetIterator initializes a new iterator.
func NewPatchsetIterator(things []*Patchset) *PatchsetIterator {
return &PatchsetIterator{things: things}
}
// Scan moves to the next element and returns false if there are no more things.
// Use Scan() in a loop, similar to a while loop
//
// for iterator.Scan()
// d := iterator.Next(
// fmt.Println("found UUID:", d.Uuid
// }
func (it *PatchsetIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *PatchsetIterator) Next() *Patchset {
if it.things[it.index-1] == nil {
for i, d := range it.things {
fmt.Println("i =", i, d)
}
}
return it.things[it.index-1]
}
func (x *Patchsets) All() *PatchsetIterator {
PatchsetPointers := x.selectAllPatchset()
iterator := NewPatchsetIterator(PatchsetPointers)
return iterator
}
func (x *Patchsets) Len() int {
x.Lock.RLock()
defer x.Lock.RUnlock()
return len(x.Patchsets)
}
// safely returns a slice of pointers to the Patchset protobufs
func (x *Patchsets) selectAllPatchset() []*Patchset {
x.Lock.RLock()
defer x.Lock.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
}
func (x *Patchsets) SortByName() *PatchsetIterator {
things := x.selectAllPatchset()
sort.Sort(PatchsetName(things))
iterator := NewPatchsetIterator(things)
return iterator
}
type PatchsetName []*Patchset
func (a PatchsetName) Len() int { return len(a) }
func (a PatchsetName) Less(i, j int) bool { return a[i].Name < a[j].Name }
func (a PatchsetName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (x *Patchsets) SortByGitAuthorName() *PatchsetIterator {
things := x.selectAllPatchset()
sort.Sort(PatchsetGitAuthorName(things))
iterator := NewPatchsetIterator(things)
return iterator
}
type PatchsetGitAuthorName []*Patchset
func (a PatchsetGitAuthorName) Len() int { return len(a) }
func (a PatchsetGitAuthorName) Less(i, j int) bool { return a[i].GitAuthorName < a[j].GitAuthorName }
func (a PatchsetGitAuthorName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }