From 74a6d4bdfbc104b93b6d6e56bda9d70e07b8b597 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 11 Mar 2025 12:15:12 -0500 Subject: [PATCH] resurrect code I deleted for 'git am' --- windowPatches.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/windowPatches.go b/windowPatches.go index f11152b..b23735b 100644 --- a/windowPatches.go +++ b/windowPatches.go @@ -5,12 +5,14 @@ package main import ( "fmt" + "os" "path/filepath" "sync" "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) @@ -57,6 +59,30 @@ func makePatchesWin(patches *forgepb.Patches) *stdPatchTableWin { grid.NewButton("reload", func() { }) + grid.NewButton("Apply All", func() { + var count int + all := 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) + }) // make a box at the bottom of the window for the protobuf table dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX") @@ -101,3 +127,23 @@ func AddPatchesPB(tbox *gui.Node, pb *forgepb.Patches) *forgepb.PatchesTable { t.ShowTable() return t } + +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 +}