Notes added by 'git notes append'
This commit is contained in:
parent
441ba06ba2
commit
389e52acf7
|
@ -2018,3 +2018,177 @@ func file_repo_proto_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// `autogen:repo.sort.pb.go`
|
// `autogen:repo.sort.pb.go`
|
||||||
|
|
||||||
|
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
||||||
|
// This file was autogenerated with autogenpb v0.0.38-3-g25ae7fc 2025.01.10_0403
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// bad global lock until modifying the .pb.go file is tested
|
||||||
|
// sync.RWMutex or sync.Mutex?
|
||||||
|
var repoMu sync.RWMutex
|
||||||
|
|
||||||
|
type RepoIterator struct {
|
||||||
|
sync.RWMutex
|
||||||
|
|
||||||
|
things []*Repo
|
||||||
|
index int
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRepoIterator initializes a new iterator.
|
||||||
|
func NewRepoIterator(things []*Repo) *RepoIterator {
|
||||||
|
return &RepoIterator{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 *RepoIterator) Scan() bool {
|
||||||
|
if it.index >= len(it.things) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
it.index++
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next() returns the next thing in the array
|
||||||
|
func (it *RepoIterator) Next() *Repo {
|
||||||
|
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 (all *Repos) All() *RepoIterator {
|
||||||
|
RepoPointers := all.selectAllRepo()
|
||||||
|
|
||||||
|
iterator := NewRepoIterator(RepoPointers)
|
||||||
|
return iterator
|
||||||
|
}
|
||||||
|
|
||||||
|
func (all *Repos) Len() int {
|
||||||
|
all.Lock.RLock()
|
||||||
|
defer all.Lock.RUnlock()
|
||||||
|
|
||||||
|
return len(all.Repos)
|
||||||
|
}
|
||||||
|
|
||||||
|
// safely returns a slice of pointers to the Repo protobufs
|
||||||
|
func (all *Repos) selectAllRepo() []*Repo {
|
||||||
|
all.Lock.RLock()
|
||||||
|
defer all.Lock.RUnlock()
|
||||||
|
|
||||||
|
// Create a new slice to hold pointers to each Repo
|
||||||
|
var tmp []*Repo
|
||||||
|
tmp = make([]*Repo, len(all.Repos))
|
||||||
|
for i, p := range all.Repos {
|
||||||
|
tmp[i] = p // Copy pointers for safe iteration
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp
|
||||||
|
}
|
||||||
|
|
||||||
|
// maybe seperate files here?
|
||||||
|
// just a simple Append() with no checking (but still uses the mutex lock)
|
||||||
|
func (all *Repos) Append(newP *Repo) bool {
|
||||||
|
all.Lock.RLock()
|
||||||
|
defer all.Lock.RUnlock()
|
||||||
|
|
||||||
|
all.Repos = append(all.Repos, newP)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// enforces Repo is unique
|
||||||
|
func (all *Repos) AppendUniqueFullPath(newP *Repo) bool {
|
||||||
|
all.Lock.RLock()
|
||||||
|
defer all.Lock.RUnlock()
|
||||||
|
|
||||||
|
for _, p := range all.Repos {
|
||||||
|
if p.FullPath == newP.FullPath {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
all.Repos = append(all.Repos, newP)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// enforces Repo is unique
|
||||||
|
func (all *Repos) AppendUnique(newP *Repo) bool {
|
||||||
|
all.Lock.RLock()
|
||||||
|
defer all.Lock.RUnlock()
|
||||||
|
|
||||||
|
for _, p := range all.Repos {
|
||||||
|
if p.FullPath == newP.FullPath {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
all.Repos = append(all.Repos, newP)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (all *Repos) SortByFullPath() *RepoIterator {
|
||||||
|
things := all.selectAllRepo()
|
||||||
|
|
||||||
|
sort.Sort(RepoFullPath(things))
|
||||||
|
|
||||||
|
iterator := NewRepoIterator(things)
|
||||||
|
return iterator
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepoFullPath []*Repo
|
||||||
|
|
||||||
|
func (a RepoFullPath) Len() int { return len(a) }
|
||||||
|
func (a RepoFullPath) Less(i, j int) bool { return a[i].FullPath < a[j].FullPath }
|
||||||
|
func (a RepoFullPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
|
||||||
|
func (all *Repos) DeleteByFullPath(s string) bool {
|
||||||
|
all.Lock.RLock()
|
||||||
|
defer all.Lock.RUnlock()
|
||||||
|
|
||||||
|
for i, _ := range all.Repos {
|
||||||
|
if all.Repos[i].FullPath == s {
|
||||||
|
all.Repos[i] = all.Repos[len(all.Repos)-1]
|
||||||
|
all.Repos = all.Repos[:len(all.Repos)-1]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// find a dependancy by the go path
|
||||||
|
func (all *Repos) FindByFullPath(s string) *Repo {
|
||||||
|
if all == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
all.Lock.RLock()
|
||||||
|
defer all.Lock.RUnlock()
|
||||||
|
|
||||||
|
for i, _ := range all.Repos {
|
||||||
|
if all.Repos[i].FullPath == s {
|
||||||
|
return all.Repos[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue