diff --git a/configfile.go b/configfile.go deleted file mode 100644 index 02314b2..0000000 --- a/configfile.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "os" - "path/filepath" - - "go.wit.com/lib/protobuf/forgepb" - "go.wit.com/log" - "google.golang.org/protobuf/proto" -) - -func LoadPatchsets() error { - me.all = forgepb.NewPatchsets() - - filename := filepath.Join(LIBDIR, "all-patches.pb") - - data, err := os.ReadFile(filename) - if err != nil { - return err - } - - err = me.all.Unmarshal(data) - if err != nil { - log.Infof("LoadPatchsets() proto.Marshal() error %v\n", err) - return err - } - log.Infof("LoadPatchsets() worked ok %d\n", me.all.Len()) - return nil -} - -func SavePatchsets() error { - filename := filepath.Join(LIBDIR, "all-patches.pb") - 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) - // fmt.Fprintln(w, "filename open error:", filename, err) - return err - } - defer regfile.Close() - - newpb := proto.Clone(me.all).(*forgepb.Patchsets) - if newpb == nil { - for pset := range me.all.IterAll() { - showPatchsets(pset) - } - return log.Errorf("SavePatchsets() Clone failed!") - } - - data, err := newpb.Marshal() - if err != nil { - log.Infof("SavePatchset() proto.Marshal() error %v\n", err) - return err - } - log.Infof("SavePatchset() worked (%d) bytes\n", len(data)) - regfile.Write(data) - return nil -} diff --git a/doList.go b/doList.go index ce4f6ac..382c083 100644 --- a/doList.go +++ b/doList.go @@ -1,9 +1,6 @@ package main import ( - "regexp" - "strings" - "go.wit.com/lib/protobuf/forgepb" "go.wit.com/log" ) @@ -11,56 +8,32 @@ import ( func doList() error { log.Info("do list here") - if err := LoadPatchsets(); err != nil { + if err := me.forge.LoadPatchsets(); err != nil { badExit(err) } // first show the general patchset protobuf - for pb := range me.all.IterAll() { + for pb := range me.forge.Patchsets.IterAll() { if pb.Name == "forge auto commit" { - showPatchsets(pb) + pb.ShowPatchsets() } } // show all the patchsets with Names - for pset := range me.all.IterAll() { + for pset := range me.forge.Patchsets.IterAll() { if pset.Name == "forge auto commit" { continue } - showPatchsets(pset) + pset.ShowPatchsets() } return nil } -func cleanSubject(line string) string { - // Regular expression to remove "Subject:" and "[PATCH...]" patterns - re := regexp.MustCompile(`(?i)^Subject:\s*(\[\s*PATCH[^\]]*\]\s*)?`) - cleaned := re.ReplaceAllString(line, "") - return strings.TrimSpace(cleaned) -} - -func showPatchsets(pb *forgepb.Patchset) error { - author := "Author: " + pb.GitAuthorName - author += " <" + pb.GitAuthorEmail + ">" - log.Printf("%-16s %s %s %s\n", string(pb.Uuid)[0:8], pb.Name, pb.Comment, author) - for _, patch := range pb.Patches.Patches { - comment := cleanSubject(patch.Comment) - log.Printf("\t%-8s %-50s %-50s\n", string(patch.CommitHash)[0:8], patch.Namespace, comment) - } - /* - for patch := range pb.IterAll() { - comment := cleanSubject(patch.Comment) - log.Info("\tnew patch:", patch.NewHash, "commithash:", patch.CommitHash, patch.Namespace, comment) - } - */ - return nil -} - // returns true if the patch already exists in the protobuf func findPatch(newpatch *forgepb.Patch) bool { // log.Info("\tlook for patch:", newpatch.CommitHash, newpatch.Namespace) - for pset := range me.all.IterAll() { + for pset := range me.forge.Patchsets.IterAll() { for _, patch := range pset.Patches.Patches { if patch.CommitHash == newpatch.CommitHash { // log.Info("\tfound pset!!!!!!", pset.Uuid, patch.Namespace) diff --git a/doMerge.go b/doMerge.go index ad1c45e..7603b34 100644 --- a/doMerge.go +++ b/doMerge.go @@ -14,7 +14,7 @@ import ( func doMerge() error { mergePatchsets() - if err := SavePatchsets(); err != nil { + if err := me.forge.SavePatchsets(); err != nil { log.Warn("savePatchsets() failed", err) return err } @@ -22,7 +22,7 @@ func doMerge() error { } func findAutoPatchset() *forgepb.Patchset { - for pset := range me.all.IterAll() { + for pset := range me.forge.Patchsets.IterAll() { if pset.Name == "forge auto commit" { return pset break @@ -36,7 +36,7 @@ func findAutoPatchset() *forgepb.Patchset { fauto.Name = "forge auto commit" fauto.Patches = forgepb.NewPatches() fauto.Uuid = uuid.New().String() - me.all.Patchsets = append(me.all.Patchsets, fauto) + me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, fauto) } return fauto } @@ -88,18 +88,18 @@ func addPatchset(filename string, pb *forgepb.Patchset) { // if you got here, this patchset was submitted with a name // Has this patchset already been submitted? - for pset := range me.all.IterAll() { + for pset := range me.forge.Patchsets.IterAll() { if pset.Uuid == pb.Uuid { log.Info("ALREADY ADDED", pset.Uuid, pset.Name) return } } - // Clone() this protobuf into me.all + // Clone() this protobuf into me.forge.Patchsets var newpb *forgepb.Patchset newpb = proto.Clone(pb).(*forgepb.Patchset) if newpb != nil { - me.all.Patchsets = append(me.all.Patchsets, newpb) + me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, newpb) } } diff --git a/main.go b/main.go index c74409b..734d257 100644 --- a/main.go +++ b/main.go @@ -48,12 +48,14 @@ func main() { os.Setenv("FORGE_GOSRC", "/home/forge") } - if err := LoadPatchsets(); err != nil { - if argv.Force == true { - me.all = forgepb.NewPatchsets() - } else { - badExit(err) - } + if os.Getenv("FORGE_PATCHDIR") == "" { + os.Setenv("FORGE_PATCHDIR", "/var/lib/forged") + } + + me.forge = forgepb.RawInitPB() + + if err := me.forge.LoadPatchsets(); err != nil { + badExit(err) } if argv.List != nil { diff --git a/structs.go b/structs.go index b40d6e4..41fec14 100644 --- a/structs.go +++ b/structs.go @@ -12,7 +12,7 @@ var me *mainType // this app's variables type mainType struct { - pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + forge *forgepb.Forge // for holding the forge protobuf files // myGui *gui.Node // the gui toolkit handle - all *forgepb.Patchsets }