better patch window

This commit is contained in:
Jeff Carr 2025-03-12 08:17:23 -05:00
parent 369c252a68
commit 6cf3648b94
3 changed files with 50 additions and 36 deletions

View File

@ -4,6 +4,7 @@
package main
import (
"fmt"
"os"
"path/filepath"
@ -40,13 +41,12 @@ func doPatch() error {
}
func doPatchList() error {
psets, err := openPatchsets()
if err != nil {
log.Info("Open Patchsets failed", err)
return err
openPatchsets()
if me.psets == nil {
return fmt.Errorf("Open Patchsets failed")
}
log.Info("got psets len", len(psets.Patchsets))
all := psets.SortByName()
log.Info("got psets len", len(me.psets.Patchsets))
all := me.psets.SortByName()
for all.Scan() {
pset := all.Next()
// log.Info("pset name =", pset.Name)
@ -55,8 +55,11 @@ func doPatchList() error {
return nil
}
func savePatchsets(psets *forgepb.Patchsets) error {
data, err := psets.Marshal()
func savePatchsets() error {
if me.psets == nil {
return fmt.Errorf("savePatchesets() can't save nil")
}
data, err := me.psets.Marshal()
if err != nil {
log.Info("protobuf.Marshal() failed:", err)
return err
@ -73,21 +76,21 @@ func savePatchsets(psets *forgepb.Patchsets) error {
return nil
}
func openPatchsets() (*forgepb.Patchsets, error) {
func openPatchsets() {
fullpath := filepath.Join(me.forge.GetConfigDir(), "patchsets.pb")
data, err := os.ReadFile(fullpath)
if err != nil {
log.Info("Patchsets open failed:", err, fullpath)
return nil, err
return
}
psets := new(forgepb.Patchsets)
err = psets.Unmarshal(data)
if err != nil {
log.Info("Unmarshal patchsets failed", err)
return nil, err
return
}
return psets, nil
me.psets = psets
}
// returns bad if patches can not be applied
@ -169,8 +172,7 @@ func doPatchGet() error {
dumpPatchset(pset)
}
if err := savePatchsets(psets); err != nil {
return err
}
log.Info("FIXME: can't save these yet. must merge with on disk psets here")
// savePatchsets()
return nil
}

View File

@ -23,13 +23,14 @@ func (b *mainType) Enable() {
// this app's variables
type mainType struct {
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
forge *forgepb.Forge // for holding the forge protobuf files
myGui *gui.Node // the gui toolkit handle
found *gitpb.Repos // stores the list of repos to process things on
foundPaths []string // stores gopaths to act on (when doing go-clone)
configSave bool // if the config file should be saved after finishing
urlbase string // base URL
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
forge *forgepb.Forge // for holding the forge protobuf files
myGui *gui.Node // the gui toolkit handle
found *gitpb.Repos // stores the list of repos to process things on
psets *forgepb.Patchsets // the locally stored on disk patchsets
foundPaths []string // stores gopaths to act on (when doing go-clone)
configSave bool // if the config file should be saved after finishing
urlbase string // base URL
// our view of the repositories
// patchWin *patchesWindow

View File

@ -39,41 +39,52 @@ func makePatchsetsWin() *stdPatchsetTableWin {
}
grid := dwin.win.Group.RawGrid()
grid.NewButton("reload", func() {
grid.NewButton("ondisk", func() {
openPatchsets()
if me.psets == nil {
log.Info("No Patchsets loaded")
return
}
dwin.doPatchsetsTable(me.psets)
})
grid.NewButton("upstream", func() {
psets, err := me.forge.GetPatchesets()
if err != nil {
log.Info("Get Patchsets failed", err)
return
}
savePatchsets(psets)
dwin.doPatchsetsTable(psets)
})
grid.NewButton("analyse patchsets", func() {
psets, err := openPatchsets()
if err != nil {
log.Info("Open Patchsets failed", err)
grid.NewButton("analyse and save patchsets", func() {
if me.psets == nil {
log.Info("No Patchsets loaded")
return
}
all := psets.All()
all := me.psets.All()
for all.Scan() {
pset := all.Next()
log.Info("What is up with?", pset.Name)
setPatchsetState(pset)
if pset.State == "" {
log.Info("What is up with?", pset.Name)
setPatchsetState(pset)
} else {
log.Info("patchset already had state", pset.Name, pset.State)
}
}
savePatchsets(psets)
savePatchsets()
})
// make a box at the bottom of the window for the protobuf table
dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX")
// load and show the current patch sets
psets, err := openPatchsets()
if err != nil {
log.Info("Open Patchsets failed", err)
openPatchsets()
if me.psets == nil {
log.Info("Open Patchsets failed")
return dwin
}
dwin.doPatchsetsTable(psets)
dwin.doPatchsetsTable(me.psets)
return dwin
}