diff options
| author | Jeff Carr <[email protected]> | 2025-09-05 01:24:20 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-05 01:24:20 -0500 |
| commit | 04028e61817ccc8b3c33976aedbf1ada2736eb10 (patch) | |
| tree | f0c341723acfc786dd262b9385796a5ea3d0fdf5 /windowPatches.go | |
| parent | c5025d25b2cb8306539f43c836063e0b55e49792 (diff) | |
more stuff
Diffstat (limited to 'windowPatches.go')
| -rw-r--r-- | windowPatches.go | 117 |
1 files changed, 67 insertions, 50 deletions
diff --git a/windowPatches.go b/windowPatches.go index ad42076..31ed924 100644 --- a/windowPatches.go +++ b/windowPatches.go @@ -39,6 +39,7 @@ func makePatchesWin(patches *forgepb.Patches) *stdPatchTableWin { dwin.win = gadgets.NewGenericWindow("current patches", "patching options") dwin.win.Custom = func() { log.Info("test delete window here") + dwin.win.Hide() // dwin = nil } grid := dwin.win.Group.RawGrid() @@ -57,31 +58,10 @@ func makePatchesWin(patches *forgepb.Patches) *stdPatchTableWin { grid.NewLabel(fmt.Sprintf("total repos")) grid.NextRow() - grid.NewButton("show all", func() { - /* - if me.psets == nil { - log.Info("No Patchsets loaded") - return - } - notdone := new(forgepb.Patches) - - all := me.psets.All() - for all.Scan() { - pset := all.Next() - AddNotDonePatches(notdone, pset, true) - } - - for patch := range notdone.IterAll() { - comment := cleanSubject(patch.Comment) - log.Info("new patch:", patch.NewHash, "commithash:", patch.CommitHash, patch.Namespace, comment) - } - dwin.doPatchesTable(notdone) - */ - }) - grid.NewButton("Update", func() { - log.Info("TODO: run forge.GetPatches() here") - // me.forge.GetPatches() + log.Info("TODO: doesn't update this window") + me.forge.GetPatches() + dwin.win.Custom() // loadUpstreamPatchsets() }) @@ -90,24 +70,22 @@ func makePatchesWin(patches *forgepb.Patches) *stdPatchTableWin { all := patches.SortByFilename() for all.Scan() { p := all.Next() - rn := p.Namespace - 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 { - cmd := []string{"git", "am", "--abort"} - err := repo.RunVerbose(cmd) - log.Info("warn user of git am error", err) - return - } + applyPatchNew(p) + /* + rn := p.Namespace + repo := me.forge.FindByGoPath(rn) + if repo == nil { + log.Info("Could not figure out repo path", rn) + return + } + count += 1 + if _, err := applyAndTrackPatch(repo, p); err != nil { + cmd := []string{"git", "am", "--abort"} + err := repo.RunVerbose(cmd) + log.Info("warn user of git am error", err) + return + } + */ } log.Info("ALL PATCHES WORKED! count =", count) }) @@ -126,17 +104,13 @@ func applyPatchNew(p *forgepb.Patch) error { rn := p.Namespace repo := me.forge.FindByGoPath(rn) if repo == nil { - return fmt.Errorf("Could not figure out repo path %s", rn) + log.Info("Could not figure out repo path", rn) + return log.Errorf("%s namespace?\n", rn) } - filename, err := savePatch(p) - if err != nil { - log.Info("savePatch() failed", err) - return err - } - if err := applyPatch(repo, filename); err != nil { - log.Info("warn user of git am error", err) + if _, err := applyAndTrackPatch(repo, p); err != nil { cmd := []string{"git", "am", "--abort"} err := repo.RunVerbose(cmd) + log.Info("warn user of git am error", err) return err } return nil @@ -222,3 +196,46 @@ func savePatch(p *forgepb.Patch) (string, error) { return tmpname, nil } + +func applyAndTrackPatch(repo *gitpb.Repo, 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() + + cmd := []string{"git", "am", tmpname} + err = repo.RunVerbose(cmd) + if err != nil { + log.Info("git am failed. run 'git am --abort' here") + return "", log.Errorf("git am failed") + } + + log.Info("Try to find hash value now") + + p.NewHash = "fixme applyAndTrack" + if setNewHash(p, p.NewHash) { + log.Info("setting NewHash worked", p.NewHash) + } + me.forge.SavePatchsets() + + return p.NewHash, log.Errorf("did not lookup new hash") +} + +func setNewHash(p *forgepb.Patch, hash string) bool { + for pset := range me.forge.Patchsets.IterAll() { + for patch := range pset.Patches.IterAll() { + if patch.CommitHash == hash { + patch.NewHash = hash + log.Info("found patch in repo") + me.forge.SavePatchsets() + return true + } + } + } + return false +} |
