Notes added by 'git notes append'
This commit is contained in:
parent
f29352b766
commit
dbc04f0de3
|
@ -1634,3 +1634,432 @@ func file_patchset_proto_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// `autogen:patchset.sort.pb.go`
|
// `autogen:patchset.sort.pb.go`
|
||||||
|
|
||||||
|
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
||||||
|
// This file was autogenerated with autogenpb v0.0.54 2025-02-15_02:56:28_UTC
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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 ITERATOR.
|
||||||
|
// itializes a new iterator.
|
||||||
|
func newPatchsetsIterator(things []*Patchsets) *PatchsetsIterator {
|
||||||
|
return &PatchsetsIterator{things: things}
|
||||||
|
}
|
||||||
|
|
||||||
|
type PatchsetsIterator struct {
|
||||||
|
sync.RWMutex // this isn't getting used properly yet?
|
||||||
|
|
||||||
|
things []*Patchsets
|
||||||
|
index int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *PatchsetsIterator) Scan() bool {
|
||||||
|
if it.index >= len(it.things) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
it.index++
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next() returns the next thing in the array
|
||||||
|
func (it *PatchsetsIterator) Next() *Patchsets {
|
||||||
|
if it.things[it.index-1] == nil {
|
||||||
|
fmt.Println("Next() error in PatchsetsIterator", it.index)
|
||||||
|
}
|
||||||
|
return it.things[it.index-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// END DEFINE THE ITERATOR
|
||||||
|
|
||||||
|
// DEFINE THE Patchset ITERATOR.
|
||||||
|
// itializes a new iterator.
|
||||||
|
func newPatchsetIterator(things []*Patchset) *PatchsetIterator {
|
||||||
|
return &PatchsetIterator{things: things}
|
||||||
|
}
|
||||||
|
|
||||||
|
type PatchsetIterator struct {
|
||||||
|
sync.RWMutex // this isn't getting used properly yet?
|
||||||
|
|
||||||
|
things []*Patchset
|
||||||
|
index int
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
fmt.Println("Next() error in PatchsetIterator", it.index)
|
||||||
|
}
|
||||||
|
return it.things[it.index-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// END DEFINE THE ITERATOR
|
||||||
|
|
||||||
|
// DEFINE THE Identify ITERATOR.
|
||||||
|
// itializes a new iterator.
|
||||||
|
func newIdentifyIterator(things []*Identify) *IdentifyIterator {
|
||||||
|
return &IdentifyIterator{things: things}
|
||||||
|
}
|
||||||
|
|
||||||
|
type IdentifyIterator struct {
|
||||||
|
sync.RWMutex // this isn't getting used properly yet?
|
||||||
|
|
||||||
|
things []*Identify
|
||||||
|
index int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IdentifyIterator) Scan() bool {
|
||||||
|
if it.index >= len(it.things) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
it.index++
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next() returns the next thing in the array
|
||||||
|
func (it *IdentifyIterator) Next() *Identify {
|
||||||
|
if it.things[it.index-1] == nil {
|
||||||
|
fmt.Println("Next() error in IdentifyIterator", it.index)
|
||||||
|
}
|
||||||
|
return it.things[it.index-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// END DEFINE THE ITERATOR
|
||||||
|
|
||||||
|
// DEFINE THE Patch ITERATOR.
|
||||||
|
// itializes a new iterator.
|
||||||
|
func newPatchIterator(things []*Patch) *PatchIterator {
|
||||||
|
return &PatchIterator{things: things}
|
||||||
|
}
|
||||||
|
|
||||||
|
type PatchIterator struct {
|
||||||
|
sync.RWMutex // this isn't getting used properly yet?
|
||||||
|
|
||||||
|
things []*Patch
|
||||||
|
index int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *PatchIterator) Scan() bool {
|
||||||
|
if it.index >= len(it.things) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
it.index++
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next() returns the next thing in the array
|
||||||
|
func (it *PatchIterator) Next() *Patch {
|
||||||
|
if it.things[it.index-1] == nil {
|
||||||
|
fmt.Println("Next() error in PatchIterator", it.index)
|
||||||
|
}
|
||||||
|
return it.things[it.index-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// END DEFINE THE ITERATOR
|
||||||
|
|
||||||
|
// DEFINE THE Patches ITERATOR.
|
||||||
|
// itializes a new iterator.
|
||||||
|
func newPatchesIterator(things []*Patches) *PatchesIterator {
|
||||||
|
return &PatchesIterator{things: things}
|
||||||
|
}
|
||||||
|
|
||||||
|
type PatchesIterator struct {
|
||||||
|
sync.RWMutex // this isn't getting used properly yet?
|
||||||
|
|
||||||
|
things []*Patches
|
||||||
|
index int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *PatchesIterator) Scan() bool {
|
||||||
|
if it.index >= len(it.things) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
it.index++
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next() returns the next thing in the array
|
||||||
|
func (it *PatchesIterator) Next() *Patches {
|
||||||
|
if it.things[it.index-1] == nil {
|
||||||
|
fmt.Println("Next() error in PatchesIterator", it.index)
|
||||||
|
}
|
||||||
|
return it.things[it.index-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// END DEFINE THE ITERATOR
|
||||||
|
|
||||||
|
// sort struct by Name
|
||||||
|
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] }
|
||||||
|
|
||||||
|
// sort struct by GitAuthorName
|
||||||
|
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] }
|
||||||
|
|
||||||
|
// sort struct by Filename
|
||||||
|
type PatchFilename []*Patch
|
||||||
|
|
||||||
|
func (a PatchFilename) Len() int { return len(a) }
|
||||||
|
func (a PatchFilename) Less(i, j int) bool { return a[i].Filename < a[j].Filename }
|
||||||
|
func (a PatchFilename) 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 {
|
||||||
|
x.RLock()
|
||||||
|
defer x.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 {
|
||||||
|
x.RLock()
|
||||||
|
defer x.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() *PatchsetIterator {
|
||||||
|
// copy the pointers as fast as possible.
|
||||||
|
things := x.selectAllPatchsets()
|
||||||
|
|
||||||
|
// todo: try slices.SortFunc() instead to see what happens
|
||||||
|
sort.Sort(PatchsetName(things))
|
||||||
|
// slices.SortFunc(things, func(a, b *Patchsets) bool {
|
||||||
|
// return a.Name < b.Name // Sort by ??. let the compiler work it out??
|
||||||
|
// })
|
||||||
|
return newPatchsetIterator(things)
|
||||||
|
}
|
||||||
|
func (x *Patchsets) SortByGitAuthorName() *PatchsetIterator {
|
||||||
|
// copy the pointers as fast as possible.
|
||||||
|
things := x.selectAllPatchsets()
|
||||||
|
|
||||||
|
// todo: try slices.SortFunc() instead to see what happens
|
||||||
|
sort.Sort(PatchsetGitAuthorName(things))
|
||||||
|
// slices.SortFunc(things, func(a, b *Patchsets) bool {
|
||||||
|
// return a.GitAuthorName < b.GitAuthorName // Sort by ??. let the compiler work it out??
|
||||||
|
// })
|
||||||
|
return newPatchsetIterator(things)
|
||||||
|
}
|
||||||
|
func (x *Patches) SortByFilename() *PatchIterator {
|
||||||
|
// copy the pointers as fast as possible.
|
||||||
|
things := x.selectAllPatches()
|
||||||
|
|
||||||
|
// todo: try slices.SortFunc() instead to see what happens
|
||||||
|
sort.Sort(PatchFilename(things))
|
||||||
|
// slices.SortFunc(things, func(a, b *Patches) bool {
|
||||||
|
// return a.Filename < b.Filename // Sort by ??. let the compiler work it out??
|
||||||
|
// })
|
||||||
|
return newPatchIterator(things)
|
||||||
|
}
|
||||||
|
|
||||||
|
// END SORT
|
||||||
|
|
||||||
|
func (x *Patchsets) Len() int {
|
||||||
|
x.RLock()
|
||||||
|
defer x.RUnlock()
|
||||||
|
|
||||||
|
return len(x.Patchsets)
|
||||||
|
}
|
||||||
|
|
||||||
|
// just a simple Append() shortcut (but still uses the mutex lock)
|
||||||
|
func (x *Patchsets) Append(y *Patchset) {
|
||||||
|
x.Lock()
|
||||||
|
defer x.Unlock()
|
||||||
|
|
||||||
|
x.Patchsets = append(x.Patchsets, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Patches) Len() int {
|
||||||
|
x.RLock()
|
||||||
|
defer x.RUnlock()
|
||||||
|
|
||||||
|
return len(x.Patches)
|
||||||
|
}
|
||||||
|
|
||||||
|
// just a simple Append() shortcut (but still uses the mutex lock)
|
||||||
|
func (x *Patches) Append(y *Patch) {
|
||||||
|
x.Lock()
|
||||||
|
defer x.Unlock()
|
||||||
|
|
||||||
|
x.Patches = append(x.Patches, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Patchsets) All() *PatchsetIterator {
|
||||||
|
PatchsetPointers := x.selectAllPatchsets()
|
||||||
|
|
||||||
|
iterator := newPatchsetIterator(PatchsetPointers)
|
||||||
|
return iterator
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Patches) All() *PatchIterator {
|
||||||
|
PatchPointers := x.selectAllPatches()
|
||||||
|
|
||||||
|
iterator := newPatchIterator(PatchPointers)
|
||||||
|
return iterator
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Patchsets) Delete(y *Patchset) bool {
|
||||||
|
x.Lock()
|
||||||
|
defer x.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 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
|
||||||
|
}
|
||||||
|
|
||||||
|
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) 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, y)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue