summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.go1
-rw-r--r--configfile.go17
-rw-r--r--doList.go2
-rw-r--r--doMerge.go38
-rw-r--r--forged.service2
-rw-r--r--main.go11
6 files changed, 43 insertions, 28 deletions
diff --git a/argv.go b/argv.go
index 27b7ce9..edd6fdc 100644
--- a/argv.go
+++ b/argv.go
@@ -18,6 +18,7 @@ type args struct {
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"`
+ Daemon bool `arg:"--daemon" help:"run as a daemon"`
Force bool `arg:"--force" help:"try to strong arm things"`
Verbose bool `arg:"--verbose" help:"show more output"`
Bash bool `arg:"--bash" help:"generate bash completion"`
diff --git a/configfile.go b/configfile.go
index f2f39af..02314b2 100644
--- a/configfile.go
+++ b/configfile.go
@@ -9,7 +9,7 @@ import (
"google.golang.org/protobuf/proto"
)
-func loadConfigfile() error {
+func LoadPatchsets() error {
me.all = forgepb.NewPatchsets()
filename := filepath.Join(LIBDIR, "all-patches.pb")
@@ -21,38 +21,37 @@ func loadConfigfile() error {
err = me.all.Unmarshal(data)
if err != nil {
- log.Infof("loadConfigfile() proto.Marshal() error %v\n", err)
+ log.Infof("LoadPatchsets() proto.Marshal() error %v\n", err)
return err
}
- log.Infof("loadConfigfile() worked ok %d\n", me.all.Len())
+ log.Infof("LoadPatchsets() worked ok %d\n", me.all.Len())
return nil
}
-func savePatchsets() error {
+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)
+ log.Info("SavePatchsets() filename open error:", filename, err)
// fmt.Fprintln(w, "filename open error:", filename, err)
return err
}
defer regfile.Close()
- log.Info("GOT HERE")
newpb := proto.Clone(me.all).(*forgepb.Patchsets)
if newpb == nil {
for pset := range me.all.IterAll() {
showPatchsets(pset)
}
- return log.Errorf("Clone failed!")
+ return log.Errorf("SavePatchsets() Clone failed!")
}
data, err := newpb.Marshal()
if err != nil {
- log.Infof("savePatchset() proto.Marshal() error %v\n", err)
+ log.Infof("SavePatchset() proto.Marshal() error %v\n", err)
return err
}
- log.Infof("savePatchset() worked (%d) bytes\n", len(data))
+ log.Infof("SavePatchset() worked (%d) bytes\n", len(data))
regfile.Write(data)
return nil
}
diff --git a/doList.go b/doList.go
index 1bacb7c..ce4f6ac 100644
--- a/doList.go
+++ b/doList.go
@@ -11,7 +11,7 @@ import (
func doList() error {
log.Info("do list here")
- if err := loadConfigfile(); err != nil {
+ if err := LoadPatchsets(); err != nil {
badExit(err)
}
diff --git a/doMerge.go b/doMerge.go
index 3362c9d..ad1c45e 100644
--- a/doMerge.go
+++ b/doMerge.go
@@ -12,17 +12,9 @@ import (
)
func doMerge() error {
- if err := loadConfigfile(); err != nil {
- if argv.Force == true {
- me.all = forgepb.NewPatchsets()
- } else {
- return err
- }
- }
-
mergePatchsets()
- if err := savePatchsets(); err != nil {
+ if err := SavePatchsets(); err != nil {
log.Warn("savePatchsets() failed", err)
return err
}
@@ -30,7 +22,6 @@ func doMerge() error {
}
func findAutoPatchset() *forgepb.Patchset {
-
for pset := range me.all.IterAll() {
if pset.Name == "forge auto commit" {
return pset
@@ -71,7 +62,10 @@ func addRandomPatch(patch *forgepb.Patch) error {
return nil
}
+// adds a patchset or just the patches
func addPatchset(filename string, pb *forgepb.Patchset) {
+ // if the name of the patchset is "forge auto commit"
+ // then just add all the patches
if pb.Name == "forge auto commit" {
author := "Author: " + pb.GitAuthorName
author += " <" + pb.GitAuthorEmail + ">"
@@ -88,15 +82,25 @@ func addPatchset(filename string, pb *forgepb.Patchset) {
addRandomPatch(patch)
}
}
- // 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.Patchsets = append(me.all.Patchsets, newpb)
+ return
+ }
+
+ // if you got here, this patchset was submitted with a name
+
+ // Has this patchset already been submitted?
+ for pset := range me.all.IterAll() {
+ if pset.Uuid == pb.Uuid {
+ log.Info("ALREADY ADDED", pset.Uuid, pset.Name)
+ return
}
}
+
+ // Clone() this protobuf into me.all
+ var newpb *forgepb.Patchset
+ newpb = proto.Clone(pb).(*forgepb.Patchset)
+ if newpb != nil {
+ me.all.Patchsets = append(me.all.Patchsets, newpb)
+ }
}
func mergePatchsets() {
diff --git a/forged.service b/forged.service
index 232228c..2ecf170 100644
--- a/forged.service
+++ b/forged.service
@@ -4,7 +4,7 @@ Description=forged
[Service]
User=root
Type=simple
-ExecStart=/usr/bin/forged
+ExecStart=/usr/bin/forged --daemon
ExecStop=killall forged
Restart=on-failure
RestartSec=5
diff --git a/main.go b/main.go
index 893c20d..2eae239 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,7 @@ import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
+ "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
)
@@ -47,6 +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 argv.List != nil {
doList()
okExit("")
@@ -64,6 +73,7 @@ func main() {
okExit("")
}
+ // if argv.Daemon == true {
http.HandleFunc("/", okHandler)
// go https() // use caddy instead
p := fmt.Sprintf(":%d", argv.Port)
@@ -74,6 +84,7 @@ func main() {
if err != nil {
log.Println("Error starting server:", err)
}
+ // }
}
func formatDuration(d time.Duration) string {