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

View File

@ -27,6 +27,7 @@ type mainType struct {
forge *forgepb.Forge // for holding the forge protobuf files forge *forgepb.Forge // for holding the forge protobuf files
myGui *gui.Node // the gui toolkit handle myGui *gui.Node // the gui toolkit handle
found *gitpb.Repos // stores the list of repos to process things on 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) foundPaths []string // stores gopaths to act on (when doing go-clone)
configSave bool // if the config file should be saved after finishing configSave bool // if the config file should be saved after finishing
urlbase string // base URL urlbase string // base URL

View File

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