Notes added by 'git notes append'
This commit is contained in:
parent
28ce8cc3a7
commit
f313c8d622
|
@ -349,3 +349,250 @@ func file_gitTag_proto_init() {
|
|||
}
|
||||
|
||||
// `autogen:gitTag.sort.pb.go`
|
||||
|
||||
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
||||
// This file was autogenerated with autogenpb v0.0.44-1-g97c65be 2025.01.16_1743
|
||||
// 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"
|
||||
"sort"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// a simple global lock
|
||||
var gitTagMu sync.RWMutex
|
||||
|
||||
// START SORT
|
||||
|
||||
// DEFINE THE GitTags ITERATOR.
|
||||
// itializes a new iterator.
|
||||
func newGitTagsIterator(things []*GitTags) *GitTagsIterator {
|
||||
return &GitTagsIterator{things: things}
|
||||
}
|
||||
|
||||
type GitTagsIterator struct {
|
||||
sync.RWMutex // this isn't getting used properly yet?
|
||||
|
||||
things []*GitTags
|
||||
index int
|
||||
}
|
||||
|
||||
func (it *GitTagsIterator) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.index++
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *GitTagsIterator) Next() *GitTags {
|
||||
if it.things[it.index-1] == nil {
|
||||
fmt.Println("Next() error in GitTagsIterator", it.index)
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
// END DEFINE THE ITERATOR
|
||||
|
||||
// DEFINE THE GitTag ITERATOR.
|
||||
// itializes a new iterator.
|
||||
func newGitTagIterator(things []*GitTag) *GitTagIterator {
|
||||
return &GitTagIterator{things: things}
|
||||
}
|
||||
|
||||
type GitTagIterator struct {
|
||||
sync.RWMutex // this isn't getting used properly yet?
|
||||
|
||||
things []*GitTag
|
||||
index int
|
||||
}
|
||||
|
||||
func (it *GitTagIterator) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.index++
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *GitTagIterator) Next() *GitTag {
|
||||
if it.things[it.index-1] == nil {
|
||||
fmt.Println("Next() error in GitTagIterator", it.index)
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
// END DEFINE THE ITERATOR
|
||||
|
||||
// sort struct by Refname
|
||||
type GitTagRefname []*GitTag
|
||||
|
||||
func (a GitTagRefname) Len() int { return len(a) }
|
||||
func (a GitTagRefname) Less(i, j int) bool { return a[i].Refname < a[j].Refname }
|
||||
func (a GitTagRefname) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
// safely returns a slice of pointers to the FRUIT protobufs
|
||||
func (x *GitTags) allGitTags() []*GitTag {
|
||||
gitTagMu.RLock()
|
||||
defer gitTagMu.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each FRUIT
|
||||
var tmp []*GitTag
|
||||
tmp = make([]*GitTag, len(x.GitTags))
|
||||
for i, p := range x.GitTags {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
||||
// safely returns a slice of pointers to the GitTag protobufs
|
||||
func (x *GitTags) selectAllGitTags() []*GitTag {
|
||||
gitTagMu.RLock()
|
||||
defer gitTagMu.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each GitTag
|
||||
var tmp []*GitTag
|
||||
tmp = make([]*GitTag, len(x.GitTags))
|
||||
for i, p := range x.GitTags {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
func (x *GitTags) SortByRefname() *GitTagIterator {
|
||||
// copy the pointers as fast as possible.
|
||||
things := x.selectAllGitTags()
|
||||
|
||||
// todo: try slices.SortFunc() instead to see what happens
|
||||
sort.Sort(GitTagRefname(things))
|
||||
// slices.SortFunc(things, func(a, b *GitTags) bool {
|
||||
// return a.Refname < b.Refname // Sort by ??. let the compiler work it out??
|
||||
// })
|
||||
return newGitTagIterator(things)
|
||||
}
|
||||
|
||||
// END SORT
|
||||
|
||||
func (x *GitTags) Len() int {
|
||||
gitTagMu.RLock()
|
||||
defer gitTagMu.RUnlock()
|
||||
|
||||
return len(x.GitTags)
|
||||
}
|
||||
|
||||
// just a simple Append() shortcut (but still uses the mutex lock)
|
||||
func (x *GitTags) Append(y *GitTag) {
|
||||
gitTagMu.Lock()
|
||||
defer gitTagMu.Unlock()
|
||||
|
||||
x.GitTags = append(x.GitTags, y)
|
||||
}
|
||||
|
||||
func (x *GitTags) All() *GitTagIterator {
|
||||
GitTagPointers := x.selectAllGitTags()
|
||||
|
||||
iterator := newGitTagIterator(GitTagPointers)
|
||||
return iterator
|
||||
}
|
||||
|
||||
// lookup a GitTags by the Refname
|
||||
func (x *GitTags) FindByRefname(s string) *GitTag {
|
||||
if x == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
gitTagMu.RLock()
|
||||
defer gitTagMu.RUnlock()
|
||||
|
||||
for i, _ := range x.GitTags {
|
||||
if x.GitTags[i].Refname == s {
|
||||
return x.GitTags[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// lookup a GitTags by the Hash
|
||||
func (x *GitTags) FindByHash(s string) *GitTag {
|
||||
if x == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
gitTagMu.RLock()
|
||||
defer gitTagMu.RUnlock()
|
||||
|
||||
for i, _ := range x.GitTags {
|
||||
if x.GitTags[i].Hash == s {
|
||||
return x.GitTags[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *GitTags) DeleteByRefname(s string) bool {
|
||||
gitTagMu.Lock()
|
||||
defer gitTagMu.Unlock()
|
||||
|
||||
for i, _ := range x.GitTags {
|
||||
if x.GitTags[i].Refname == s {
|
||||
x.GitTags[i] = x.GitTags[len(x.GitTags)-1]
|
||||
x.GitTags = x.GitTags[:len(x.GitTags)-1]
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *GitTags) DeleteByHash(s string) bool {
|
||||
gitTagMu.Lock()
|
||||
defer gitTagMu.Unlock()
|
||||
|
||||
for i, _ := range x.GitTags {
|
||||
if x.GitTags[i].Hash == s {
|
||||
x.GitTags[i] = x.GitTags[len(x.GitTags)-1]
|
||||
x.GitTags = x.GitTags[:len(x.GitTags)-1]
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *GitTags) AppendByRefname(y *GitTag) bool {
|
||||
gitTagMu.Lock()
|
||||
defer gitTagMu.Unlock()
|
||||
|
||||
for _, p := range x.GitTags {
|
||||
if p.Refname == y.Refname {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
x.GitTags = append(x.GitTags, y)
|
||||
return true
|
||||
}
|
||||
|
||||
func (x *GitTags) AppendByHash(y *GitTag) bool {
|
||||
gitTagMu.Lock()
|
||||
defer gitTagMu.Unlock()
|
||||
|
||||
for _, p := range x.GitTags {
|
||||
if p.Hash == y.Hash {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
x.GitTags = append(x.GitTags, y)
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue