summaryrefslogtreecommitdiff
path: root/patchset.config.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-22 11:09:20 -0500
committerJeff Carr <[email protected]>2025-10-22 11:09:20 -0500
commitc82e607abc006f074d3d38347e0f053a5d801b1e (patch)
treeb2b7b4327470d26e5ef39f58c03ab3690d3d4c3d /patchset.config.go
parentd9e9ebe34eeb550af4c8ba3a27d9304974b9ccb1 (diff)
start adding patch "Sets" back
Diffstat (limited to 'patchset.config.go')
-rw-r--r--patchset.config.go86
1 files changed, 40 insertions, 46 deletions
diff --git a/patchset.config.go b/patchset.config.go
index 7b807d4..a8b34f4 100644
--- a/patchset.config.go
+++ b/patchset.config.go
@@ -1,20 +1,27 @@
package forgepb
-/*
+import (
+ "fmt"
+ "os"
+ "regexp"
+ "strings"
+
+ "github.com/google/uuid"
+ "go.wit.com/lib/ENV"
+ "go.wit.com/lib/config"
+ "go.wit.com/lib/protobuf/gitpb"
+ "go.wit.com/log"
+ "google.golang.org/protobuf/proto"
+)
+
func (f *Forge) InitPatchsets() error {
- if err := f.LoadPatchsets(); err == nil {
- return nil
- } else {
- log.Info("LoadPatchsets() failed", err)
- }
- // TODO: check if Unmarshal failed here
- f.Patchsets = NewSets()
- f.findAutoPatchset() // adds the default values
- return f.SavePatchsets()
+ f.Sets = NewSets()
+ err := config.LoadCacheDir(f.Sets)
+ return err
}
func (f *Forge) SavePatchsets() error {
- filename := config.Get("PatchPB")
+ filename := ENV.Get("PatchPB")
regfile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
log.Info("SavePatchsets() filename open error:", filename, err)
@@ -23,9 +30,9 @@ func (f *Forge) SavePatchsets() error {
}
defer regfile.Close()
- newpb := proto.Clone(f.Patchsets).(*Sets)
+ newpb := proto.Clone(f.Sets).(*Sets)
if newpb == nil {
- for pset := range f.Patchsets.IterAll() {
+ for pset := range f.Sets.IterAll() {
pset.ShowPatchsets()
}
return log.Errorf("SavePatchsets() Clone failed!")
@@ -36,7 +43,7 @@ func (f *Forge) SavePatchsets() error {
log.Infof("SavePatchset() proto.Marshal() error %v\n", err)
return err
}
- log.Infof("SavePatchset() worked (%d) bytes on %d patches\n", len(data), f.Patchsets.Len())
+ log.Infof("SavePatchset() worked (%d) bytes on %d patches\n", len(data), f.Sets.Len())
regfile.Write(data)
return nil
}
@@ -107,7 +114,7 @@ func (f *Forge) AddPatchset(pb *Set) bool {
// if you got here, this patchset was submitted with a name
// Has this patchset already been submitted?
- for pset := range f.Patchsets.IterAll() {
+ for pset := range f.Sets.IterAll() {
if pset.Uuid == pb.Uuid {
log.Info("ALREADY ADDED", pset.Uuid, pset.Name)
return false
@@ -115,26 +122,10 @@ func (f *Forge) AddPatchset(pb *Set) bool {
}
}
- f.Patchsets.Append(pb)
+ f.Sets.Append(pb)
return true
}
-func (f *Forge) findAutoPatchset() *Set {
- for pset := range f.Patchsets.IterAll() {
- if pset.Name == "forge auto commit" {
- return pset
- }
- }
-
- var fauto *Set
- log.Warn("findAutoPatchset() had to create 'forge auto commit'")
- if fauto == nil {
- fauto = makeDefaultPatchset()
- f.Patchsets.Append(fauto)
- }
- return fauto
-}
-
func makeDefaultPatchset() *Set {
fauto := new(Set)
fauto.Name = "forge auto commit"
@@ -146,25 +137,29 @@ func makeDefaultPatchset() *Set {
// adds submitted patches not
// If the patch was actually new, return true
func (f *Forge) AddNewPatch(patch *Patch) bool {
- // ignore patch if it's already here
- if f.findPatch(patch) {
- log.Info("already found patch", patch.CommitHash, patch.Namespace)
- return false
- }
- fauto := f.findAutoPatchset()
- if fauto == nil {
- // should have made the default patchset
- return false
- }
- fauto.Patches.Append(patch)
- return true
+ log.Info("todo: fix this. find where to add the patch")
+ return false
+ /*
+ // ignore patch if it's already here
+ if f.findPatch(patch) {
+ log.Info("already found patch", patch.CommitHash, patch.Namespace)
+ return false
+ }
+ fauto := f.findAutoPatchset()
+ if fauto == nil {
+ // should have made the default patchset
+ return false
+ }
+ fauto.Patches.Append(patch)
+ return true
+ */
}
// returns true if the patch already exists in the protobuf
func (f *Forge) findPatch(newpatch *Patch) bool {
// log.Info("\tlook for patch:", newpatch.CommitHash, newpatch.Namespace)
- for pset := range f.Patchsets.IterAll() {
+ for pset := range f.Sets.IterAll() {
for _, patch := range pset.Patches.Patches {
if patch.CommitHash == newpatch.CommitHash {
// log.Info("\tfound pset!!!!!!", pset.Uuid, patch.Namespace)
@@ -186,4 +181,3 @@ func (f *Forge) IsPatchApplied(newpatch *Patch) (*gitpb.Repo, bool) {
}
return nil, false
}
-*/