try merging patches together
This commit is contained in:
parent
6b6b31eef6
commit
c193af11e7
7
Makefile
7
Makefile
|
@ -4,9 +4,8 @@ VERSION = $(shell git describe --tags)
|
||||||
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||||
|
|
||||||
all: install
|
all: install
|
||||||
forged pull
|
forged merge
|
||||||
# ./forged list
|
# forged list
|
||||||
forged list
|
|
||||||
|
|
||||||
build: goimports
|
build: goimports
|
||||||
GO111MODULE=off go build \
|
GO111MODULE=off go build \
|
||||||
|
@ -16,7 +15,7 @@ verbose:
|
||||||
GO111MODULE=off go build -v -x \
|
GO111MODULE=off go build -v -x \
|
||||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
install:
|
install: goimports
|
||||||
GO111MODULE=off go install \
|
GO111MODULE=off go install \
|
||||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
|
|
1
argv.go
1
argv.go
|
@ -14,6 +14,7 @@ var argv args
|
||||||
type args struct {
|
type args struct {
|
||||||
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
|
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
|
||||||
List *EmptyCmd `arg:"subcommand:list" help:"list 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"`
|
Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"`
|
||||||
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
||||||
Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"`
|
Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"`
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
142
doList.go
142
doList.go
|
@ -1,10 +1,150 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func doList() any {
|
func doList() error {
|
||||||
log.Info("do list here")
|
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
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -97,45 +97,6 @@ func getPatchset(w http.ResponseWriter, pbname string) {
|
||||||
w.Write(data)
|
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 {
|
func savePatchset(w http.ResponseWriter, msg []byte) error {
|
||||||
// log.Info("proto.Unmarshal() try message len", len(msg))
|
// log.Info("proto.Unmarshal() try message len", len(msg))
|
||||||
var m *forgepb.Patchset
|
var m *forgepb.Patchset
|
||||||
|
|
5
http.go
5
http.go
|
@ -32,7 +32,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text")
|
w.Header().Set("Content-Type", "text")
|
||||||
fmt.Fprintf(w, "go.wit.com/apps/utils/forged Version: %s\n", argv.Version())
|
fmt.Fprintf(w, "go.wit.com/apps/utils/forged Version: %s\n", argv.Version())
|
||||||
fmt.Fprintf(w, "\n")
|
fmt.Fprintf(w, "\n")
|
||||||
listPatchsets(w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,10 +83,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/patchsetlist" {
|
|
||||||
listPatchsets(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if route == "/patchsetget" {
|
if route == "/patchsetget" {
|
||||||
filename := r.URL.Query().Get("filename")
|
filename := r.URL.Query().Get("filename")
|
||||||
getPatchset(w, filename)
|
getPatchset(w, filename)
|
||||||
|
|
5
main.go
5
main.go
|
@ -52,6 +52,11 @@ func main() {
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if argv.Merge != nil {
|
||||||
|
doMerge()
|
||||||
|
okExit("")
|
||||||
|
}
|
||||||
|
|
||||||
if argv.Pull != nil {
|
if argv.Pull != nil {
|
||||||
log.Info("pull here")
|
log.Info("pull here")
|
||||||
okExit("")
|
okExit("")
|
||||||
|
|
|
@ -5,6 +5,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var me *mainType
|
var me *mainType
|
||||||
|
@ -13,4 +14,5 @@ var me *mainType
|
||||||
type mainType struct {
|
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!
|
||||||
// myGui *gui.Node // the gui toolkit handle
|
// myGui *gui.Node // the gui toolkit handle
|
||||||
|
all *forgepb.Patchsets
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue