summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.go6
-rw-r--r--patchset.config.go82
-rw-r--r--structs.go2
3 files changed, 90 insertions, 0 deletions
diff --git a/init.go b/init.go
index 1470af5..a736bcf 100644
--- a/init.go
+++ b/init.go
@@ -238,6 +238,12 @@ func RawInitPB() *Forge {
log.Info("got forge url", f.forgeURL)
}
+ // where patches are stored
+ f.patchDir = f.goSrc
+ if os.Getenv("FORGE_PATCHDIR") != "" {
+ f.patchDir = os.Getenv("FORGE_PATCHDIR")
+ }
+
// todo: play with these / determine good values based on user's machine
f.rillX = 10
f.rillY = 20
diff --git a/patchset.config.go b/patchset.config.go
new file mode 100644
index 0000000..d931299
--- /dev/null
+++ b/patchset.config.go
@@ -0,0 +1,82 @@
+package forgepb
+
+import (
+ "os"
+ "path/filepath"
+ "regexp"
+ "strings"
+
+ "go.wit.com/log"
+ "google.golang.org/protobuf/proto"
+)
+
+func (f *Forge) LoadPatchsets() error {
+ f.Patchsets = NewPatchsets()
+
+ filename := filepath.Join(f.patchDir, "all-patches.pb")
+
+ data, err := os.ReadFile(filename)
+ if err != nil {
+ return err
+ }
+
+ err = f.Patchsets.Unmarshal(data)
+ if err != nil {
+ log.Infof("LoadPatchsets() proto.Marshal() error %v\n", err)
+ return err
+ }
+ log.Infof("LoadPatchsets() worked ok %d\n", f.Patchsets.Len())
+ return nil
+}
+
+func (f *Forge) SavePatchsets() error {
+ filename := filepath.Join(f.patchDir, "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(f.Patchsets).(*Patchsets)
+ if newpb == nil {
+ for pset := range f.Patchsets.IterAll() {
+ pset.ShowPatchsets()
+ }
+ 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
+}
+
+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 (pb *Patchset) ShowPatchsets() 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
+}
diff --git a/structs.go b/structs.go
index b924c69..30823c0 100644
--- a/structs.go
+++ b/structs.go
@@ -24,6 +24,8 @@ type Forge struct {
forgeURL string // URL to use to forge.wit.com
rillX int // used for Rill()
rillY int // used for Rill()
+ Patchsets *Patchsets // patches that are in progress
+ patchDir string // where patches are stored
}
func (f *Forge) GetGoSrc() string {