From 54b50299f394b45da0f46bf47715cac79ca837f0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 29 Jan 2025 11:23:34 -0600 Subject: [PATCH] slim down this window to keep it functional --- windowPatches.go | 50 +--------------------------- windowViewPatch.go | 81 +++++++++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 82 deletions(-) diff --git a/windowPatches.go b/windowPatches.go index 4642d4d..decd2ab 100644 --- a/windowPatches.go +++ b/windowPatches.go @@ -114,16 +114,7 @@ func (r *patchesWindow) addPatchset(line string) { r.setgrid.NewLabel(name) r.setgrid.NewLabel(subject) r.setgrid.NewLabel(author) - /* - r.setgrid.NewButton("Download", func() { - pset, err := savePatch(name) - if err != nil { - log.Info(name, "failed to download", err) - return - } - r.setlist[name] = pset - }) - */ + r.setgrid.NewButton("View", func() { // has the window already been created? win := r.setwin[name] @@ -143,44 +134,5 @@ func (r *patchesWindow) addPatchset(line string) { r.setwin[name] = makePatchWindow(pset) r.setwin[name].Show() }) - r.setgrid.NewButton("Dump", func() { - pset := r.setlist[name] - if pset == nil { - log.Info(name, "was nil") - return - } - if !dumpPatchset(pset) { - log.Info("Dump: some patches are bad", name) - return - } - }) - r.setgrid.NewButton("Extract", func() { - pset := r.setlist[name] - if pset == nil { - log.Info(name, "was nil") - return - } - if err := savePatchset(pset); err != nil { - log.Info("Save: some patches are bad", name, err) - return - } - }) - r.setgrid.NewButton("Apply", func() { - pset := r.setlist[name] - if pset == nil { - log.Info(name, "was nil") - return - } - if _, _, _, err := IsEverythingOnDevel(); err != nil { - log.Info("You can only apply patches to the devel branch") - return - } - if IsAnythingDirty() { - log.Info("You can't apply patches when repos are dirty") - me.forge.PrintHumanTable(me.found) - return - } - applyPatchset(pset) - }) r.setgrid.NextRow() } diff --git a/windowViewPatch.go b/windowViewPatch.go index 4ea414d..d4b9689 100644 --- a/windowViewPatch.go +++ b/windowViewPatch.go @@ -1,11 +1,11 @@ package main import ( - "strings" "sync" "go.wit.com/lib/gadgets" "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" "go.wit.com/gui" @@ -85,13 +85,13 @@ func makePatchWindow(pset *forgepb.Patchset) *patchWindow { grid.NewLabel(pset.EndBranchHash) grid.NextRow() - grid.NewButton("Extract", func() { + grid.NewButton("Extract files to disk", func() { if err := savePatchset(pset); err != nil { log.Info("Save err:", err) return } }) - grid.NewButton("Apply", func() { + grid.NewButton("Apply with git am", func() { if _, _, _, err := IsEverythingOnDevel(); err != nil { log.Info("You can only apply patches to the devel branch") return @@ -108,39 +108,54 @@ func makePatchWindow(pset *forgepb.Patchset) *patchWindow { g := pw.stack.NewGroup("PatchSet List") - // add the patch grid + // make a grid and a header filegrid := g.NewGrid("", 0, 0) + filegrid.NewLabel("repo") + filegrid.NewLabel("patch name") + filegrid.NewLabel("Applied in current branch?") + filegrid.NewLabel("start hash") + filegrid.NextRow() - all := pset.Patches.SortByFilename() - for all.Scan() { - p := all.Next() - // if IsValidPatch(p) { - filegrid.NewLabel(p.RepoNamespace) - filegrid.NewLabel(p.Comment) - filegrid.NewLabel(p.Filename) - filegrid.NewLabel(p.RepoPath) - filegrid.NewLabel(p.BranchName) - filegrid.NewLabel(p.BranchHash) - filegrid.NewLabel(p.CommitHash) - filegrid.NewLabel(p.StartHash) - filegrid.NextRow() - } - + // add the patches to the grid + pw.addPatchset(filegrid, pset) return pw } -func (r *patchWindow) addPatchset(line string) { - parts := strings.Split(line, "Author:") - author := parts[1] - parts = strings.Fields(parts[0]) - name := parts[0] - subject := strings.Join(parts[1:], " ") - r.setgrid.NewLabel(name) - r.setgrid.NewLabel(subject) - r.setgrid.NewLabel(author) - r.setgrid.NewButton("Download", func() { - }) - r.setgrid.NewButton("Apply", func() { - }) - r.setgrid.NextRow() +func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) { + repomap := make(map[*gitpb.Repo][]*forgepb.Patch) + repohash := make(map[*gitpb.Repo]string) + + // sort patches by repo namespace + all := pset.Patches.SortByFilename() + for all.Scan() { + p := all.Next() + s := p.RepoNamespace + repo := me.forge.FindByGoPath(s) + if repo == nil { + log.Info("COULD NOT FIND", s) + continue + } + repomap[repo] = append(repomap[repo], p) + repohash[repo] = p.StartHash + } + + // var repo *gitpb.Repo + + for repo, patches := range repomap { + log.Info(repo.GetGoPath()) + grid.NewLabel(repo.GetGoPath()) + + for i, p := range patches { + log.Info(i, p.Filename) + grid.NewLabel(p.Comment) + grid.NewLabel("in current branch?") + break + } + hash := repohash[repo] + grid.NewLabel(hash) + grid.NewButton("View", func() { + log.Info("todo: show patches for repo", repo.GetGoPath()) + }) + grid.NextRow() + } }