From 1b145d1f04e4cd0e83f1c603af13803f0027fabb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 10 Mar 2025 17:14:59 -0500 Subject: [PATCH] rm old code --- windowForgePatchsets.go | 73 -------- windowNewPatchsets.go | 7 +- windowNewPatches.go => windowPatches.go | 18 +- windowPatchset.go | 211 ------------------------ 4 files changed, 21 insertions(+), 288 deletions(-) rename windowNewPatches.go => windowPatches.go (82%) delete mode 100644 windowPatchset.go diff --git a/windowForgePatchsets.go b/windowForgePatchsets.go index c212f1d..c71f384 100644 --- a/windowForgePatchsets.go +++ b/windowForgePatchsets.go @@ -132,84 +132,11 @@ func (r *patchesWindow) submitPatchesBox() { // r.addPatchsetNew(pset) }) - psets, err := openPatchsets() - if err != nil { - log.Info("Open Patchsets failed", err) - } - - grid.NewButton("Update Patchset List", func() { - psets, err = me.forge.GetPatchesets() - if err != nil { - log.Info("Get Patchsets failed", err) - return - } - savePatchsets(psets) - - /* - log.Info("got psets len", len(psets.Patchsets)) - all := psets.SortByName() - for all.Scan() { - pset := all.Next() - r.addPatchsetNew(pset) - } - */ - }) - // disables the submit button until the user enters a name r.submitB.Disable() grid.NextRow() - - g := r.stack.NewGroup("Patchset List") - // add the grid - r.psetgrid = g.RawGrid() - - // will look in ~/.config/forge for an existing patchset file - // attempt to read in patchsets saved on disk - - if psets != nil { - log.Info("got psets len", len(psets.Patchsets)) - /* - all := psets.SortByName() - for all.Scan() { - pset := all.Next() - log.Info("pset name =", pset.Name) - r.addPatchsetNew(pset) - } - */ - } } -/* -func (r *patchesWindow) addPatchsetNew(pset *forgepb.Patchset) { - var win *patchWindow - r.psetgrid.NewButton("View", func() { - // has the window already been created? - if win != nil { - win.Toggle() - return - } - - // win = makePatchWindow(pset) - // win.Show() - }) - r.psetgrid.NewLabel(pset.Name) - r.psetgrid.NewLabel(pset.Comment) - r.psetgrid.NewLabel(pset.GitAuthorName) - r.psetgrid.NewLabel(pset.Uuid) - - ctime := pset.Ctime.AsTime() - stime := ctime.UTC().Format("2006-01-02_15:04:05_UTC") - r.psetgrid.NewLabel(stime) - if pset.State == "BROKEN" { - r.psetgrid.NewLabel("Bad") - } else { - r.psetgrid.NewLabel("Good") - } - - r.psetgrid.NextRow() -} -*/ - // will update this from the current state of the protobuf func (r *patchesWindow) Update() { var total, dirty, readonly, rw int diff --git a/windowNewPatchsets.go b/windowNewPatchsets.go index 2b8bb46..f6517c1 100644 --- a/windowNewPatchsets.go +++ b/windowNewPatchsets.go @@ -39,7 +39,7 @@ func makePatchsetsWin() *stdPatchsetTableWin { } grid := dwin.win.Group.RawGrid() - grid.NewButton("reload current patches", func() { + grid.NewButton("reload", func() { psets, err := me.forge.GetPatchesets() if err != nil { log.Info("Get Patchsets failed", err) @@ -118,8 +118,9 @@ func AddPatchsetsPB(tbox *gui.Node, pb *forgepb.Patchsets) *forgepb.PatchsetsTab }) vp.Custom = func(pset *forgepb.Patchset) { log.Info("show patches here", pset.Name) - patchwin := makePatchesWin() - patchwin.doPatchesTable(pset.Patches) + makePatchesWin(pset.Patches) + // patchwin := makePatchesWin() + // patchwin.doPatchesTable(pset.Patches) /* win := makePatchWindow(pset) win.Show() diff --git a/windowNewPatches.go b/windowPatches.go similarity index 82% rename from windowNewPatches.go rename to windowPatches.go index 2d9f29c..5735872 100644 --- a/windowNewPatches.go +++ b/windowPatches.go @@ -30,7 +30,7 @@ func (w *stdPatchTableWin) Toggle() { w.win.Toggle() } -func makePatchesWin() *stdPatchTableWin { +func makePatchesWin(p *forgepb.Patches) *stdPatchTableWin { dwin := new(stdPatchTableWin) dwin.win = gadgets.NewGenericWindow("current patches", "patching options") dwin.win.Custom = func() { @@ -39,12 +39,28 @@ func makePatchesWin() *stdPatchTableWin { } grid := dwin.win.Group.RawGrid() + grid.NewLabel(fmt.Sprintf("%d", p.Len()) + grid.NewLabel(fmt.Sprintf("total patches") + grid.NextRow() + + all := p.All() + for all.Scan() { + repo := all.Next() + } + grid.NewLabel(fmt.Sprintf("%d", p.Len()) + grid.NewLabel(fmt.Sprintf("total repos") + grid.NextRow() + grid.NewButton("reload", func() { }) // make a box at the bottom of the window for the protobuf table dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX") + if p != nil { + dwin.doPatchesTable(p) + } + return dwin } diff --git a/windowPatchset.go b/windowPatchset.go deleted file mode 100644 index 9eda8df..0000000 --- a/windowPatchset.go +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright 2017-2025 WIT.COM Inc. All rights reserved. -// Use of this source code is governed by the GPL 3.0 - -package main - -/* -type patchWindow 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 - setgrid *gui.Node // the list of each patchset - pset *forgepb.Patchset // the patchset in question -} - -// todo: autogenerate these or make them standared 'gui' package functions -// make this an go interface somehow - -// is the window hidden right now? -func (w *patchWindow) Hidden() bool { - return w.win.Hidden() -} - -// switches between the window being visable or hidden on the desktop -func (w *patchWindow) Toggle() { - if w.Hidden() { - w.Show() - } else { - w.Hide() - } -} - -// hides the window completely -func (w *patchWindow) Show() { - w.win.Show() -} - -func (w *patchWindow) Hide() { - w.win.Hide() -} - -// should be the first box/widget in the window -// greys out the window to the user -func (w *patchWindow) Disable() { - w.stack.Disable() -} - -func (w *patchWindow) Enable() { - w.stack.Enable() -} - -// you can only have one of these -func makePatchWindow(pset *forgepb.Patchset) *patchWindow { - pw := new(patchWindow) - - // sync.Once() - pw.win = gadgets.RawBasicWindow("Patcheset for " + pset.Name + " (" + pset.Comment + ")") - pw.win.Make() - - pw.stack = pw.win.Box().NewBox("bw vbox", false) - // me.reposwin.Draw() - pw.win.Custom = func() { - // sets the hidden flag to false so Toggle() works - pw.win.Hide() - } - - grid := pw.stack.NewGrid("", 0, 0) - - grid.NewLabel("Patchset Details:") - grid.NewLabel(pset.GitAuthorName) - grid.NewLabel(pset.GitAuthorEmail) - grid.NewLabel("start branch: " + pset.StartBranchName) - grid.NewLabel(pset.StartBranchHash) - grid.NewLabel("end branch: " + pset.EndBranchName) - grid.NewLabel(pset.EndBranchHash) - grid.NewButton("Apply All", func() { - var count int - all := pset.Patches.SortByFilename() - for all.Scan() { - p := all.Next() - rn := p.RepoNamespace - repo := me.forge.FindByGoPath(rn) - if repo == nil { - log.Info("Could not figure out repo path", rn) - return - } - filename, err := savePatch(p) - if err != nil { - log.Info("savePatch() failed", err) - return - } - count += 1 - if err := applyPatch(repo, filename); err != nil { - log.Info("warn user of git am error", err) - return - } - } - log.Info("ALL PATCHES WORKED! count =", count) - }) - grid.NextRow() - - g := pw.stack.NewGroup("PatchSet List") - - // make a grid to put the list of git repos that have patches - // in this particular patchset - grid = g.NewGrid("", 0, 0) - grid.NewLabel("repo") - grid.NewLabel("patch name") - grid.NewLabel("Applied in current branch?") - grid.NewLabel("start hash") - grid.NewLabel("") - grid.NextRow() - - // add the patches to the grid - pw.addPatchset(grid, pset) - return pw -} - -func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) { - all := pset.Patches.SortByFilename() - for all.Scan() { - p := all.Next() - // for repo, patches := range repomap { - rn := p.RepoNamespace - repo := me.forge.FindByGoPath(rn) - if repo == nil { - log.Info("Could not figure out repo path", rn) - rn += " bad repo" - } - log.Info("Adding patches for", rn) - grid.NewLabel(rn) - - // hash := repohash[repo] - grid.NewLabel(p.StartHash) - grid.NewLabel(p.Filename) - - if repo == nil { - continue - } - // var win *repoPatchWindow - grid.NewButton("apply", func() { - filename, _ := savePatch(p) - if err := applyPatch(repo, filename); err != nil { - log.Info("warn user of git am error", err) - } - // win = makeRepoPatchWindow(repo, p) - // win.Show() - }) - grid.NewCheckbox("").SetChecked(true) - grid.NewCheckbox("").SetChecked(true) - grid.NewButton("save patch to /tmp", func() { - savePatch(p) - // for _, pat := range patches { - // } - }) - grid.NextRow() - } -} - -func applyPatch(repo *gitpb.Repo, filename string) error { - cmd := []string{"git", "am", filename} - err := repo.RunVerbose(cmd) - return err -} - -func savePatch(p *forgepb.Patch) (string, error) { - _, filen := filepath.Split(p.Filename) - tmpname := filepath.Join("/tmp", filen) - log.Info("saving as", tmpname, p.Filename) - raw, err := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) - if err != nil { - return "", err - } - raw.Write(p.Data) - raw.Close() - - return tmpname, nil -} - -// saves the patches in ~/.config/forge/currentpatches/ -func savePatchset(pset *forgepb.Patchset) error { - log.Info("savePatches() NAME", pset.Name) - log.Info("savePatches() COMMENT", pset.Comment) - log.Info("savePatches() GIT_AUTHOR_NAME", pset.GetGitAuthorName()) - log.Info("savePatches() GIT_AUTHOR_EMAIL", pset.GetGitAuthorEmail()) - log.Info("savePatches() Branch Name", pset.GetStartBranchName()) - log.Info("savePatches() Start Hash", pset.GetStartBranchHash()) - - var count int - var bad int - var lasterr error - all := pset.Patches.SortByFilename() - for all.Scan() { - p := all.Next() - basedir := filepath.Join(os.Getenv("FORGE_CONFIG"), "currentpatches") - if fullname, err := savePatchFile(p, basedir); err != nil { - log.Info(fullname, "save failed", err) - bad += 1 - lasterr = err - } - count += 1 - } - log.Info("pset has", count, "total patches, ", bad, "bad save patches") - if bad == 0 { - return lasterr - } - return nil -} -*/