playing with the patch windows

This commit is contained in:
Jeff Carr 2025-02-02 16:17:48 -06:00
parent f8e13c6cd8
commit 6aafc842ae
2 changed files with 117 additions and 61 deletions

View File

@ -14,6 +14,7 @@ import (
"go.wit.com/log"
)
/*
// saves the patches in ~/.config/forge/currentpatches/
func savePatchset(pset *forgepb.Patchset) error {
log.Info("savePatches() NAME", pset.Name)
@ -43,6 +44,7 @@ func savePatchset(pset *forgepb.Patchset) error {
}
return nil
}
*/
// re-run git CheckDirty() on everything
func IsAnythingDirty() bool {
@ -71,7 +73,7 @@ func countCurrentPatches(repo *gitpb.Repo) int {
return len(result.Stdout)
}
func applyPatchset(pset *forgepb.Patchset) error {
func applyPatchsetOLD(pset *forgepb.Patchset) error {
var everythingworked bool = true
tmpdir, err := os.MkdirTemp("", "forge")
if err != nil {

View File

@ -10,7 +10,6 @@ import (
"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"
@ -99,26 +98,28 @@ func makePatchWindow(pset *forgepb.Patchset) *patchWindow {
grid.NewLabel("Applied in current branch?")
grid.NewLabel("start hash")
grid.NewLabel("")
grid.NewButton("Extract", func() {
if err := savePatchset(pset); err != nil {
log.Info("Save err:", err)
return
}
})
grid.NewButton("Apply with git am", func() {
if _, _, _, err := IsEverythingOnUser(); err != nil {
log.Info("You can only apply patches to the user branch")
return
}
if IsAnythingDirty() {
log.Info("You can't apply patches when repos are dirty")
me.forge.PrintHumanTable(me.found)
return
}
if argv.Force {
applyPatchset(pset)
}
})
/*
grid.NewButton("Extract", func() {
if err := savePatchset(pset); err != nil {
log.Info("Save err:", err)
return
}
})
grid.NewButton("Apply with git am", func() {
if _, _, _, err := IsEverythingOnUser(); err != nil {
log.Info("You can only apply patches to the user branch")
return
}
if IsAnythingDirty() {
log.Info("You can't apply patches when repos are dirty")
me.forge.PrintHumanTable(me.found)
return
}
if argv.Force {
applyPatchset(pset)
}
})
*/
grid.NextRow()
// add the patches to the grid
@ -127,35 +128,53 @@ func makePatchWindow(pset *forgepb.Patchset) *patchWindow {
}
func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) {
repomap := make(map[*gitpb.Repo][]*forgepb.Patch)
repohash := make(map[*gitpb.Repo]string)
/*
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 figure out repo path", s)
continue
}
repomap[repo] = append(repomap[repo], p)
repohash[repo] = p.StartHash
}
*/
// sort patches by repo namespace
all := pset.Patches.SortByFilename()
for all.Scan() {
p := all.Next()
s := p.RepoNamespace
repo := me.forge.FindByGoPath(s)
// 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)
/*
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(p.StartHash)
grid.NewLabel(p.Filename)
if repo == nil {
log.Info("Could not figure out repo path", s)
continue
}
repomap[repo] = append(repomap[repo], p)
repohash[repo] = p.StartHash
}
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)
var win *repoPatchWindow
grid.NewButton("View", func() {
if win != nil {
@ -164,29 +183,64 @@ func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) {
return
}
win = makeRepoPatchWindow(repo, patches)
// win = makeRepoPatchWindow(repo, p)
win.Show()
})
grid.NewCheckbox("").SetChecked(true)
grid.NewCheckbox("").SetChecked(true)
grid.NewButton("save", func() {
for _, p := range patches {
_, filen := filepath.Split(p.Filename)
tmpname := filepath.Join("/tmp", filen)
log.Info("saving as", tmpname, p.Filename)
raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
raw.Write(p.Data)
raw.Close()
}
})
grid.NewButton("view hash", func() {
cmd := []string{"git", "whatchanged", hash}
log.Info(repo.GetFullPath(), cmd)
})
grid.NewButton("git am", func() {
cmd := []string{"git", "whatchanged", hash}
log.Info(repo.GetFullPath(), cmd)
// savePatchset(p)
/*
for _, p := range patches {
_, filen := filepath.Split(p.Filename)
tmpname := filepath.Join("/tmp", filen)
log.Info("saving as", tmpname, p.Filename)
raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
raw.Write(p.Data)
raw.Close()
}
*/
})
/*
grid.NewButton("view hash", func() {
cmd := []string{"git", "whatchanged", hash}
log.Info(repo.GetFullPath(), cmd)
})
grid.NewButton("git am", func() {
cmd := []string{"git", "whatchanged", hash}
log.Info(repo.GetFullPath(), cmd)
})
*/
grid.NextRow()
}
}
// 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
}