From f91a91fe94308ff9fe12c348c892b4f76f3a04a9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 11 Jan 2025 06:17:21 -0600 Subject: [PATCH] Notes added by 'git notes append' --- ed92f1d99dd3f5cdcc9fbae396def94e8634940a | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/ed92f1d99dd3f5cdcc9fbae396def94e8634940a b/ed92f1d99dd3f5cdcc9fbae396def94e8634940a index 4521ac0..09a5e22 100644 --- a/ed92f1d99dd3f5cdcc9fbae396def94e8634940a +++ b/ed92f1d99dd3f5cdcc9fbae396def94e8634940a @@ -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] }