diff --git a/0ea93faef25eda579e3c557b10ff98a766689e40 b/0ea93faef25eda579e3c557b10ff98a766689e40 index 8043cf0..5094f48 100644 --- a/0ea93faef25eda579e3c557b10ff98a766689e40 +++ b/0ea93faef25eda579e3c557b10ff98a766689e40 @@ -660,3 +660,108 @@ func (a ForgeConfigGoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPat func (a ForgeConfigGoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // `autogen:patchset.find.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 ( + "sync" +) + +// a simple global lock +var patchsetMu sync.RWMutex + +// just a simple Append() shortcut (but still uses the mutex lock) +func (x *Patchsets) Append(y *Patchset) { + x.Lock.Lock() + defer x.Lock.Unlock() + + x.Patchsets = append(x.Patchsets, y) +} + +// lookup a Patchset by the Filename +func (x *Patchset) FindByFilename(s string) *Patch { + if x == nil { + return nil + } + + patchsetMu.RLock() + defer patchsetMu.RUnlock() + + for i, _ := range x.Patches { + if x.Patches[i].Filename == s { + return x.Patches[i] + } + } + return nil +} + +// enforces Patch.Filename is unique in Patchset.Patches +func (x *Patchset) AppendUniqueFilename(newP *Patch) bool { + patchsetMu.Lock() + defer patchsetMu.Unlock() + + for _, p := range x.Patches { + if p.Filename == newP.Filename { + return false + } + } + + x.Patches = append(x.Patches, newP) + return true +} + +// enforces Patch is unique in Patchset.Patches +func (x *Patchset) AppendUnique(newP *Patch) bool { + patchsetMu.Lock() + defer patchsetMu.Unlock() + + for _, p := range x.Patches { + if p.Filename == newP.Filename { + return false + } + } + + x.Patches = append(x.Patches, newP) + return true +} + +func (x *Patchset) DeleteByFilename(s string) bool { + patchsetMu.Lock() + defer patchsetMu.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 +} + +// returns an Patch if Filename matches, otherwise create +func (x *Patchset) InsertByFilename(y string) *Patch { + patchsetMu.Lock() + defer patchsetMu.Unlock() + + for _, p := range x.Patches { + if p.Filename == y { + return p + } + } + + z := new(Patch) + z.Filename = y + x.Patches = append(x.Patches, z) + return z +}