diff --git a/bbd567092a6a6c3c136ee09b82525b2a15311256 b/bbd567092a6a6c3c136ee09b82525b2a15311256 index f4b64ad..12537d0 100644 --- a/bbd567092a6a6c3c136ee09b82525b2a15311256 +++ b/bbd567092a6a6c3c136ee09b82525b2a15311256 @@ -641,3 +641,405 @@ 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.49-2-g9a0e4a6 2025.02.01_0732 +// 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 + +func (x *GitTags) fixUuid() { + if x == nil { + return + } + if x.Uuid == "ffdff813-0316-4372-9e82-4c1c7d202526" { + return + } + x.Uuid = "ffdff813-0316-4372-9e82-4c1c7d202526" + x.Version = "v0.0.47 go.wit.com/lib/protobuf/gitpb" +} + +func NewGitTags() *GitTags { + x := new(GitTags) + x.Uuid = "ffdff813-0316-4372-9e82-4c1c7d202526" + x.Version = "v0.0.47 go.wit.com/lib/protobuf/gitpb" + return x +} + +// 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 + +// DEFINE THE GitRemote ITERATOR. +// itializes a new iterator. +func newGitRemoteIterator(things []*GitRemote) *GitRemoteIterator { + return &GitRemoteIterator{things: things} +} + +type GitRemoteIterator struct { + sync.RWMutex // this isn't getting used properly yet? + + things []*GitRemote + index int +} + +func (it *GitRemoteIterator) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.index++ + return true +} + +// Next() returns the next thing in the array +func (it *GitRemoteIterator) Next() *GitRemote { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in GitRemoteIterator", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE ITERATOR + +// DEFINE THE GitBranch ITERATOR. +// itializes a new iterator. +func newGitBranchIterator(things []*GitBranch) *GitBranchIterator { + return &GitBranchIterator{things: things} +} + +type GitBranchIterator struct { + sync.RWMutex // this isn't getting used properly yet? + + things []*GitBranch + index int +} + +func (it *GitBranchIterator) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.index++ + return true +} + +// Next() returns the next thing in the array +func (it *GitBranchIterator) Next() *GitBranch { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in GitBranchIterator", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE ITERATOR + +// DEFINE THE GitConfig ITERATOR. +// itializes a new iterator. +func newGitConfigIterator(things []*GitConfig) *GitConfigIterator { + return &GitConfigIterator{things: things} +} + +type GitConfigIterator struct { + sync.RWMutex // this isn't getting used properly yet? + + things []*GitConfig + index int +} + +func (it *GitConfigIterator) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.index++ + return true +} + +// Next() returns the next thing in the array +func (it *GitConfigIterator) Next() *GitConfig { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in GitConfigIterator", 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 FRUIT protobufs +func (x *GitConfig) allLocal() []*GitBranch { + gitTagMu.RLock() + defer gitTagMu.RUnlock() + + // Create a new slice to hold pointers to each FRUIT + var tmp []*GitBranch + tmp = make([]*GitBranch, len(x.Local)) + for i, p := range x.Local { + 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 +} + +// safely returns a slice of pointers to the GitBranch protobufs +func (x *GitConfig) selectAllLocal() []*GitBranch { + gitTagMu.RLock() + defer gitTagMu.RUnlock() + + // Create a new slice to hold pointers to each GitBranch + var tmp []*GitBranch + tmp = make([]*GitBranch, len(x.Local)) + for i, p := range x.Local { + 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 +} + +func (x *GitTags) Delete(y *GitTag) bool { + gitTagMu.Lock() + defer gitTagMu.Unlock() + + for i, _ := range x.GitTags { + if x.GitTags[i] == y { + x.GitTags[i] = x.GitTags[len(x.GitTags)-1] + x.GitTags = x.GitTags[:len(x.GitTags)-1] + return true + } + } + return false +} + +// 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 +}