test
This commit is contained in:
parent
86ac85dd5b
commit
906d50a771
1
argv.go
1
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"`
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
38
doMerge.go
38
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() {
|
||||
|
|
|
@ -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
|
||||
|
|
11
main.go
11
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 {
|
||||
|
|
Loading…
Reference in New Issue