summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--argv.go1
-rw-r--r--configfile.go48
-rw-r--r--doList.go142
-rw-r--r--doMerge.go95
-rw-r--r--doPatchsets.go39
-rw-r--r--http.go5
-rw-r--r--main.go5
-rw-r--r--structs.go2
9 files changed, 295 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index c0a9114..6b9c77b 100644
--- a/Makefile
+++ b/Makefile
@@ -4,9 +4,8 @@ VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
all: install
- forged pull
- # ./forged list
- forged list
+ forged merge
+ # forged list
build: goimports
GO111MODULE=off go build \
@@ -16,7 +15,7 @@ verbose:
GO111MODULE=off go build -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
-install:
+install: goimports
GO111MODULE=off go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
diff --git a/argv.go b/argv.go
index 1848cd3..27b7ce9 100644
--- a/argv.go
+++ b/argv.go
@@ -14,6 +14,7 @@ var argv args
type args struct {
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
List *EmptyCmd `arg:"subcommand:list" help:"list the repos"`
+ Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"`
Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"`
Port int `arg:"--port" default:"2520" help:"port to run on"`
Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"`
diff --git a/configfile.go b/configfile.go
new file mode 100644
index 0000000..51125c1
--- /dev/null
+++ b/configfile.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/log"
+)
+
+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("filename open error:", filename, err)
+ // fmt.Fprintln(w, "filename open error:", filename, err)
+ return err
+ }
+ defer regfile.Close()
+
+ data, err := me.all.Marshal()
+ if err != nil {
+ log.Infof("savePatchset() proto.Marshal() error %v\n", err)
+ return err
+ }
+ log.Infof("savePatchset() proto.Unmarshal() try to send len(msg)=%d back to the client forge\n", len(data))
+ regfile.Write(data)
+ return nil
+}
+
+func loadConfigfile() 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("loadConfigfile() savePatchset() proto.Marshal() error %v\n", err)
+ return err
+ }
+ log.Infof("loadConfigfile() worked ok %d\n", me.all.Len())
+ return nil
+}
diff --git a/doList.go b/doList.go
index 7610d13..350d15d 100644
--- a/doList.go
+++ b/doList.go
@@ -1,10 +1,150 @@
package main
import (
+ "fmt"
+
+ "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
)
-func doList() any {
+func doList() error {
log.Info("do list here")
+
+ me.all = forgepb.NewPatchsets()
+
+ /*
+ err := filepath.WalkDir("/var/lib/forged/patchset", func(path string, d os.DirEntry, err error) error {
+ if err != nil {
+ // Handle possible errors, like permission issues
+ fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
+ return err
+ }
+
+ if d.IsDir() {
+ // log.Info("path is dir", path)
+ return nil
+ } else {
+ _, fname := filepath.Split(path)
+ log.Info("found", fname, path)
+ return nil
+ }
+
+ return nil
+ })
+ */
+ for pset := range me.all.IterAll() {
+ showPatchsets(pset)
+ }
return nil
}
+
+func showPatchsets(pb *forgepb.Patchset) error {
+ author := "Author: " + pb.GitAuthorName
+ author += " <" + pb.GitAuthorEmail + ">"
+
+ // author := "Author: " + os.Getenv("GIT_AUTHOR_NAME")
+ // author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">"
+ fmt.Println(pb.Name, pb.Comment, author)
+ for i, patches := range pb.Patches.Patches {
+ log.Info("\tnew patches:", i, patches.CommitHash, patches.Namespace)
+ }
+ /*
+ for patch := range pb.IterAll() {
+ comment := cleanSubject(patch.Comment)
+ log.Info("\tnew patch:", patch.NewHash, "commithash:", patch.CommitHash, patch.Namespace, comment)
+ }
+ */
+ return nil
+}
+
+/*
+// adds submitted patches not specifically assigned to a patchset
+// to the generic patchset called "forge auto commit"
+func addRandomPatch(patch *forgepb.Patch) {
+ for pset := range me.all.IterAll() {
+ if pset.Name == "forge auto commit" {
+ newpb := proto.Clone(patch).(*forgepb.Patch)
+ if newpb != nil {
+ pset.Patches.Append(newpb)
+ }
+ }
+ }
+ log.Warn("patchset.Name == 'forge auto commit' could not be found so the patch in", patch.Namespace, "could not be added")
+}
+
+func addPatchset(filename string, pb *forgepb.Patchset) {
+ if pb.Name == "forge auto commit" {
+ author := "Author: " + pb.GitAuthorName
+ author += " <" + pb.GitAuthorEmail + ">"
+
+ // author := "Author: " + os.Getenv("GIT_AUTHOR_NAME")
+ // author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">"
+ fmt.Println(filename, pb.Name, pb.Comment, author)
+ for _, patch := range pb.Patches.Patches {
+ // log.Info("\tnew patch:", i, patch.CommitHash, patch.Namespace)
+ if findPatch(patch) {
+ // log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
+ } else {
+ log.Info("\tnew patch:", filename, pb.Name, pb.Comment, author)
+ }
+ }
+ // add each of the patches to the general pool
+ } else {
+ // Clone() this protobuf into me.all
+ var newpb *forgepb.Patchset
+ newpb = proto.Clone(pb).(*forgepb.Patchset)
+ if newpb != nil {
+ me.all.Append(newpb)
+ }
+ }
+}
+*/
+
+// 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 _, patch := range pset.Patches.Patches {
+ if patch.CommitHash == newpatch.CommitHash {
+ // log.Info("\tfound pset!!!!!!", pset.Uuid, patch.Namespace)
+ return true
+ }
+
+ }
+ }
+
+ return false
+}
+
+/*
+func mergePatchsets() {
+ dirname := filepath.Join(LIBDIR, "patchset/")
+ // Open the directory
+ entries, err := os.ReadDir(dirname)
+ if err != nil {
+ fmt.Printf("Error reading directory: %v\n", err)
+ return
+ }
+
+ // Iterate through the directory entries
+ for _, entry := range entries {
+ // Check if the entry is a file and matches the *.pb pattern
+ if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" {
+ bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name()))
+ if err != nil {
+ fmt.Println(entry.Name(), err)
+ continue
+ }
+ var p *forgepb.Patchset
+ p = new(forgepb.Patchset)
+ err = p.Unmarshal(bytes)
+ if err != nil {
+ fmt.Println(entry.Name(), err)
+ continue
+ }
+ addPatchset(entry.Name(), p)
+ }
+ }
+}
+*/
diff --git a/doMerge.go b/doMerge.go
new file mode 100644
index 0000000..f049c5c
--- /dev/null
+++ b/doMerge.go
@@ -0,0 +1,95 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/log"
+ "google.golang.org/protobuf/proto"
+)
+
+func doMerge() error {
+ if err := loadConfigfile(); err != nil {
+ badExit(err)
+ }
+
+ mergePatchsets()
+ for pset := range me.all.IterAll() {
+ showPatchsets(pset)
+ }
+ // savePatchsets()
+ return nil
+}
+
+// adds submitted patches not specifically assigned to a patchset
+// to the generic patchset called "forge auto commit"
+func addRandomPatch(patch *forgepb.Patch) {
+ for pset := range me.all.IterAll() {
+ if pset.Name == "forge auto commit" {
+ newpb := proto.Clone(patch).(*forgepb.Patch)
+ if newpb != nil {
+ pset.Patches.Append(newpb)
+ }
+ }
+ }
+ log.Warn("patchset.Name == 'forge auto commit' could not be found so the patch in", patch.Namespace, "could not be added")
+}
+
+func addPatchset(filename string, pb *forgepb.Patchset) {
+ if pb.Name == "forge auto commit" {
+ author := "Author: " + pb.GitAuthorName
+ author += " <" + pb.GitAuthorEmail + ">"
+
+ // author := "Author: " + os.Getenv("GIT_AUTHOR_NAME")
+ // author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">"
+ fmt.Println(filename, pb.Name, pb.Comment, author)
+ for _, patch := range pb.Patches.Patches {
+ // log.Info("\tnew patch:", i, patch.CommitHash, patch.Namespace)
+ if findPatch(patch) {
+ // log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
+ } else {
+ log.Info("\tnew patch:", filename, pb.Name, pb.Comment, author)
+ }
+ }
+ // add each of the patches to the general pool
+ } else {
+ // Clone() this protobuf into me.all
+ var newpb *forgepb.Patchset
+ newpb = proto.Clone(pb).(*forgepb.Patchset)
+ if newpb != nil {
+ me.all.Append(newpb)
+ }
+ }
+}
+
+func mergePatchsets() {
+ dirname := filepath.Join(LIBDIR, "patchset/")
+ // Open the directory
+ entries, err := os.ReadDir(dirname)
+ if err != nil {
+ fmt.Printf("Error reading directory: %v\n", err)
+ return
+ }
+
+ // Iterate through the directory entries
+ for _, entry := range entries {
+ // Check if the entry is a file and matches the *.pb pattern
+ if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" {
+ bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name()))
+ if err != nil {
+ fmt.Println(entry.Name(), err)
+ continue
+ }
+ var p *forgepb.Patchset
+ p = new(forgepb.Patchset)
+ err = p.Unmarshal(bytes)
+ if err != nil {
+ fmt.Println(entry.Name(), err)
+ continue
+ }
+ addPatchset(entry.Name(), p)
+ }
+ }
+}
diff --git a/doPatchsets.go b/doPatchsets.go
index caf73bc..3920ec3 100644
--- a/doPatchsets.go
+++ b/doPatchsets.go
@@ -97,45 +97,6 @@ func getPatchset(w http.ResponseWriter, pbname string) {
w.Write(data)
}
-func listPatchsets(w http.ResponseWriter) {
- dirname := filepath.Join(LIBDIR, "patchset/")
- // Open the directory
- entries, err := os.ReadDir(dirname)
- if err != nil {
- fmt.Printf("Error reading directory: %v\n", err)
- fmt.Fprintf(w, "Error reading directory: %v\n", err)
- return
- }
-
- // Iterate through the directory entries
- for _, entry := range entries {
- // Check if the entry is a file and matches the *.pb pattern
- if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" {
- bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name()))
- if err != nil {
- fmt.Fprintln(w, entry.Name(), err)
- fmt.Println(entry.Name(), err)
- continue
- }
- var p *forgepb.Patchset
- p = new(forgepb.Patchset)
- err = p.Unmarshal(bytes)
- if err != nil {
- fmt.Fprintln(w, entry.Name(), err)
- fmt.Println(entry.Name(), err)
- continue
- }
- author := "Author: " + p.GitAuthorName
- author += " <" + p.GitAuthorEmail + ">"
-
- // author := "Author: " + os.Getenv("GIT_AUTHOR_NAME")
- // author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">"
- fmt.Fprintln(w, entry.Name(), p.Name, p.Comment, author)
- fmt.Println(entry.Name(), p.Name, p.Comment, author)
- }
- }
-}
-
func savePatchset(w http.ResponseWriter, msg []byte) error {
// log.Info("proto.Unmarshal() try message len", len(msg))
var m *forgepb.Patchset
diff --git a/http.go b/http.go
index c9abaf7..06ff524 100644
--- a/http.go
+++ b/http.go
@@ -32,7 +32,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text")
fmt.Fprintf(w, "go.wit.com/apps/utils/forged Version: %s\n", argv.Version())
fmt.Fprintf(w, "\n")
- listPatchsets(w)
return
}
@@ -84,10 +83,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
- if route == "/patchsetlist" {
- listPatchsets(w)
- return
- }
if route == "/patchsetget" {
filename := r.URL.Query().Get("filename")
getPatchset(w, filename)
diff --git a/main.go b/main.go
index c82397a..4da231a 100644
--- a/main.go
+++ b/main.go
@@ -52,6 +52,11 @@ func main() {
okExit("")
}
+ if argv.Merge != nil {
+ doMerge()
+ okExit("")
+ }
+
if argv.Pull != nil {
log.Info("pull here")
okExit("")
diff --git a/structs.go b/structs.go
index 6f7efa0..b40d6e4 100644
--- a/structs.go
+++ b/structs.go
@@ -5,6 +5,7 @@ package main
import (
"go.wit.com/dev/alexflint/arg"
+ "go.wit.com/lib/protobuf/forgepb"
)
var me *mainType
@@ -13,4 +14,5 @@ var me *mainType
type mainType struct {
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
// myGui *gui.Node // the gui toolkit handle
+ all *forgepb.Patchsets
}