make a patchset grid widget

This commit is contained in:
Jeff Carr 2025-01-28 13:20:10 -06:00
parent 3b6e84abdf
commit 91c28de514
7 changed files with 171 additions and 78 deletions

View File

@ -4,7 +4,8 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
info: install
# forge dirty
# forge examine
forge clean
# forge clean
make andlabs
vet:
@GO111MODULE=off go vet

View File

@ -6,12 +6,42 @@ import (
"os"
"path/filepath"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
// saves the patches in ~/.config/forge/currentpatches/
func savePatchset(pset *forgepb.Patchset) bool {
log.Info("applyPatches() NAME", pset.Name)
log.Info("applyPatches() COMMENT", pset.Comment)
log.Info("applyPatches() GIT_AUTHOR_NAME", pset.GetGitAuthorName())
log.Info("applyPatches() GIT_AUTHOR_EMAIL", pset.GetGitAuthorEmail())
log.Info("applyPatches() Branch Name", pset.GetStartBranchName())
log.Info("applyPatches() Start Hash", pset.GetStartBranchHash())
var count int
var bad int
all := pset.Patches.SortByFilename()
for all.Scan() {
p := all.Next()
// basedir := me.forge.GetGoSrc()
basedir := filepath.Join(os.Getenv("FORGE_CONFIG"), "currentpatches")
if fullname, err := savePatchFile(p, basedir); err != nil {
log.Info(fullname, "save failed", err)
continue
} else {
bad += 1
}
count += 1
}
log.Info("pset has", count, "total patches, ", bad, "bad save patches")
if bad == 0 {
return true
}
return false
}
// returns bad if patches can not be applied
func dumpPatchset(pset *forgepb.Patchset) bool {
log.Info("applyPatches() NAME", pset.Name)
@ -99,28 +129,40 @@ func applyPatchset(pset *forgepb.Patchset) error {
all := pset.Patches.SortByFilename()
for all.Scan() {
p := all.Next()
// log.Info("pset filename FILENAME IS REAL?", p.Filename, pset.Name, pset.Comment)
basepath, filename := filepath.Split(p.Filename)
fullpath := filepath.Join(me.forge.GetGoSrc(), basepath)
log.Info("pset filename FILENAME IS REAL? fullpath", fullpath)
fullTmpdir := filepath.Join(tmpdir, basepath)
err := os.MkdirAll(fullTmpdir, os.ModePerm)
if err != nil {
log.Info("applyPathces() MkdirAll failed for", fullTmpdir)
log.Info("applyPathces() MkdirAll failed err", err)
everythingworked = false
basedir := me.forge.GetGoSrc()
if fullname, err := savePatchFile(p, basedir); err != nil {
log.Info(fullname, "save failed", err)
continue
}
log.Info("pset filename FILENAME IS REAL? tmp fullTmpdir", fullTmpdir)
tmpname := filepath.Join(fullTmpdir, filename)
raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
raw.Write(p.Data)
raw.Close()
cmd := []string{"git", "am", tmpname}
result := shell.PathRun(fullpath, cmd)
if result.Exit != 0 {
log.Info("cmd failed", cmd, result.Exit)
everythingworked = false
} else {
/*
// log.Info("pset filename FILENAME IS REAL?", p.Filename, pset.Name, pset.Comment)
basepath, filename := filepath.Split(p.Filename)
fullpath := filepath.Join(me.forge.GetGoSrc(), basepath)
log.Info("pset filename FILENAME IS REAL? fullpath", fullpath)
fullTmpdir := filepath.Join(tmpdir, basepath)
err := os.MkdirAll(fullTmpdir, os.ModePerm)
if err != nil {
log.Info("applyPathces() MkdirAll failed for", fullTmpdir)
log.Info("applyPathces() MkdirAll failed err", err)
everythingworked = false
continue
}
log.Info("pset filename FILENAME IS REAL? tmp fullTmpdir", fullTmpdir)
tmpname := filepath.Join(fullTmpdir, filename)
raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
raw.Write(p.Data)
raw.Close()
*/
/*
FIX THIS
cmd := []string{"git", "am", fullname}
result := shell.PathRun(fullpath, cmd)
if result.Exit != 0 {
log.Info("cmd failed", cmd, result.Exit)
everythingworked = false
}
*/
}
// until 'git am' works
everythingworked = false
@ -132,6 +174,23 @@ func applyPatchset(pset *forgepb.Patchset) error {
return nil
}
func savePatchFile(p *forgepb.Patch, basedir string) (string, error) {
basepath, filename := filepath.Split(p.Filename)
fulldir := filepath.Join(basedir, basepath)
err := os.MkdirAll(fulldir, os.ModePerm)
if err != nil {
log.Info("applyPathces() MkdirAll failed for", fulldir)
log.Info("applyPathces() MkdirAll failed err", err)
return "", err
}
tmpname := filepath.Join(fulldir, filename)
log.Info("pset filename FILENAME IS REAL?", tmpname)
raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
raw.Write(p.Data)
raw.Close()
return tmpname, nil
}
func readPatchFile(pbfile string) (*forgepb.Patchset, error) {
bytes, err := os.ReadFile(pbfile)
if err != nil {

View File

@ -59,14 +59,9 @@ func doGui() {
vbox2 := me.mainbox.NewVerticalBox("BOX2")
globalBuildOptions(vbox2)
// me.summary = submitPatchesBox(vbox2)
me.repos = makeRepoView()
// processing is done. update the repo summary box
// me.summary.Update()
// me.summary.submitB.Disable()
me.Enable()
// intermittently scans the status indefinitly

View File

@ -144,9 +144,13 @@ func main() {
}
if argv.Patch.List != nil {
if err := listPatches(); err != nil {
lines, err := listPatches()
if err != nil {
badExit(err)
}
for i, line := range lines {
log.Info(i, line)
}
okExit("patch list")
}
}

30
send.go
View File

@ -35,27 +35,31 @@ func sendPatches(pset *forgepb.Patchset) error {
return nil
}
func listPatches() error {
func listPatches() ([]string, error) {
var url string
url = me.urlbase + "/patchsetlist"
body, err := me.forge.HttpPost(url, nil)
if err != nil {
log.Info("httpPost() failed:", err)
return err
return nil, err
}
var last string
/*
var last string
test := strings.TrimSpace(string(body))
for _, line := range strings.Split(test, "\n") {
log.Info("patchset:", line)
last = strings.TrimSpace(line)
}
parts := strings.Fields(last)
if len(parts) == 0 {
return fmt.Errorf("listPatches() there are no patchsets at this time")
}
getPatch(parts[0])
return nil
*/
test := strings.TrimSpace(string(body))
for _, line := range strings.Split(test, "\n") {
log.Info("patchset:", line)
last = strings.TrimSpace(line)
}
parts := strings.Fields(last)
if len(parts) == 0 {
return fmt.Errorf("listPatches() there are no patchsets at this time")
}
getPatch(parts[0])
return nil
return strings.Split(test, "\n"), nil
}
func lastPatch() string {

View File

@ -1,21 +1,25 @@
package main
import (
"strings"
"sync"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
"go.wit.com/gui"
)
type patchesWindow struct {
once sync.Once // only init() the window once
win *gadgets.BasicWindow // the patches window
stack *gui.Node // the top box set as vertical
shelf *gui.Node // the first box in the stack, set as horizontal
grid *gui.Node // the list of available patches
summary *patchSummary // summary of current patches
once sync.Once // only init() the window once
win *gadgets.BasicWindow // the patches window
stack *gui.Node // the top box set as vertical
shelf *gui.Node // the first box in the stack, set as horizontal
grid *gui.Node // the list of available patches
summary *patchSummary // summary of current patches
setgrid *gui.Node // the list of each patchset
setlist map[string]*forgepb.Patchset // a map of the patch names to the protobuf
}
func (r *patchesWindow) Hidden() bool {
@ -63,20 +67,17 @@ func (r *patchesWindow) initWindow() {
r.grid = r.stack.NewGrid("", 0, 0)
r.shelf = r.initGroup()
r.summary = submitPatchesBox(r.stack)
r.summary = r.submitPatchesBox(r.stack)
r.initSetList()
}
func (r *patchesWindow) initGroup() *gui.Node {
// reposbox.SetExpand(false)
group1 := r.stack.NewGroup("stuff")
vbox := group1.Box()
// hbox.Horizontal()
vbox.Vertical()
hbox := vbox.Box().Horizontal()
/*
*/
dirty := hbox.NewCheckbox("dirty")
dirty.Custom = func() {
@ -91,7 +92,6 @@ func (r *patchesWindow) initGroup() *gui.Node {
})
hbox.NewButton("Get Patchsets", func() {
// if psets, err := me.forge.GetPatchesets(); err != nil {
psets, err := me.forge.GetPatchesets()
if err != nil {
log.Info(err)
@ -102,12 +102,54 @@ func (r *patchesWindow) initGroup() *gui.Node {
pset := all.Next()
log.Info(pset)
}
/*
if err := listPatches(); err != nil {
log.Info(err)
}
*/
})
return vbox
}
func (r *patchesWindow) initSetList() *gui.Node {
r.setgrid = r.stack.NewGrid("", 0, 0)
r.setlist = make(map[string]*forgepb.Patchset)
return nil
}
func (r *patchesWindow) addPatchset(line string) {
parts := strings.Split(line, "Author:")
author := parts[1]
parts = strings.Fields(parts[0])
name := parts[0]
subject := strings.Join(parts[1:], " ")
r.setgrid.NewLabel(name)
r.setgrid.NewLabel(subject)
r.setgrid.NewLabel(author)
r.setgrid.NewButton("Download", func() {
pset, err := getPatch(name)
if err != nil {
log.Info(name, "failed to download", err)
return
}
r.setlist[name] = pset
})
r.setgrid.NewButton("Dump", func() {
pset := r.setlist[name]
if pset == nil {
log.Info(name, "was nil")
return
}
if !dumpPatchset(pset) {
log.Info("Dump: some patches are bad", name)
return
}
})
r.setgrid.NewButton("Save", func() {
pset := r.setlist[name]
if pset == nil {
log.Info(name, "was nil")
return
}
if !savePatchset(pset) {
log.Info("Save: some patches are bad", name)
return
}
})
r.setgrid.NextRow()
}

View File

@ -35,7 +35,7 @@ type patchSummary struct {
// allp []*repolist.Patch
}
func submitPatchesBox(box *gui.Node) *patchSummary {
func (r *patchesWindow) submitPatchesBox(box *gui.Node) *patchSummary {
s := new(patchSummary)
group1 := box.NewGroup("Patch Summary")
s.grid = group1.RawGrid()
@ -75,26 +75,14 @@ func submitPatchesBox(box *gui.Node) *patchSummary {
})
s.grid.NewButton("List Patchsets", func() {
if err := listPatches(); err != nil {
log.Info(err)
}
})
s.grid.NewButton("Show Latest Patchset", func() {
lastp := lastPatch()
pset, err := getPatch(lastp)
lines, err := listPatches()
if err != nil {
log.Info(err)
return
}
if !dumpPatchset(pset) {
log.Info("some patches are bad")
return
}
if IsAnythingDirty() {
log.Info("You can't apply patches when repos are dirty")
me.forge.PrintHumanTable(me.found)
return
for i, line := range lines {
log.Info(i, line)
r.addPatchset(line)
}
})