playing with the patch windows
This commit is contained in:
parent
f8e13c6cd8
commit
6aafc842ae
|
@ -14,6 +14,7 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
// saves the patches in ~/.config/forge/currentpatches/
|
// saves the patches in ~/.config/forge/currentpatches/
|
||||||
func savePatchset(pset *forgepb.Patchset) error {
|
func savePatchset(pset *forgepb.Patchset) error {
|
||||||
log.Info("savePatches() NAME", pset.Name)
|
log.Info("savePatches() NAME", pset.Name)
|
||||||
|
@ -43,6 +44,7 @@ func savePatchset(pset *forgepb.Patchset) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// re-run git CheckDirty() on everything
|
// re-run git CheckDirty() on everything
|
||||||
func IsAnythingDirty() bool {
|
func IsAnythingDirty() bool {
|
||||||
|
@ -71,7 +73,7 @@ func countCurrentPatches(repo *gitpb.Repo) int {
|
||||||
return len(result.Stdout)
|
return len(result.Stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyPatchset(pset *forgepb.Patchset) error {
|
func applyPatchsetOLD(pset *forgepb.Patchset) error {
|
||||||
var everythingworked bool = true
|
var everythingworked bool = true
|
||||||
tmpdir, err := os.MkdirTemp("", "forge")
|
tmpdir, err := os.MkdirTemp("", "forge")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"go.wit.com/lib/gadgets"
|
"go.wit.com/lib/gadgets"
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
|
@ -99,26 +98,28 @@ func makePatchWindow(pset *forgepb.Patchset) *patchWindow {
|
||||||
grid.NewLabel("Applied in current branch?")
|
grid.NewLabel("Applied in current branch?")
|
||||||
grid.NewLabel("start hash")
|
grid.NewLabel("start hash")
|
||||||
grid.NewLabel("")
|
grid.NewLabel("")
|
||||||
grid.NewButton("Extract", func() {
|
/*
|
||||||
if err := savePatchset(pset); err != nil {
|
grid.NewButton("Extract", func() {
|
||||||
log.Info("Save err:", err)
|
if err := savePatchset(pset); err != nil {
|
||||||
return
|
log.Info("Save err:", err)
|
||||||
}
|
return
|
||||||
})
|
}
|
||||||
grid.NewButton("Apply with git am", func() {
|
})
|
||||||
if _, _, _, err := IsEverythingOnUser(); err != nil {
|
grid.NewButton("Apply with git am", func() {
|
||||||
log.Info("You can only apply patches to the user branch")
|
if _, _, _, err := IsEverythingOnUser(); err != nil {
|
||||||
return
|
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")
|
if IsAnythingDirty() {
|
||||||
me.forge.PrintHumanTable(me.found)
|
log.Info("You can't apply patches when repos are dirty")
|
||||||
return
|
me.forge.PrintHumanTable(me.found)
|
||||||
}
|
return
|
||||||
if argv.Force {
|
}
|
||||||
applyPatchset(pset)
|
if argv.Force {
|
||||||
}
|
applyPatchset(pset)
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
*/
|
||||||
grid.NextRow()
|
grid.NextRow()
|
||||||
|
|
||||||
// add the patches to the grid
|
// 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) {
|
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()
|
all := pset.Patches.SortByFilename()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
p := all.Next()
|
p := all.Next()
|
||||||
s := p.RepoNamespace
|
// for repo, patches := range repomap {
|
||||||
repo := me.forge.FindByGoPath(s)
|
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 {
|
if repo == nil {
|
||||||
log.Info("Could not figure out repo path", s)
|
|
||||||
continue
|
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
|
var win *repoPatchWindow
|
||||||
grid.NewButton("View", func() {
|
grid.NewButton("View", func() {
|
||||||
if win != nil {
|
if win != nil {
|
||||||
|
@ -164,29 +183,64 @@ func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
win = makeRepoPatchWindow(repo, patches)
|
// win = makeRepoPatchWindow(repo, p)
|
||||||
win.Show()
|
win.Show()
|
||||||
})
|
})
|
||||||
grid.NewCheckbox("").SetChecked(true)
|
grid.NewCheckbox("").SetChecked(true)
|
||||||
grid.NewCheckbox("").SetChecked(true)
|
grid.NewCheckbox("").SetChecked(true)
|
||||||
grid.NewButton("save", func() {
|
grid.NewButton("save", func() {
|
||||||
for _, p := range patches {
|
// savePatchset(p)
|
||||||
_, filen := filepath.Split(p.Filename)
|
/*
|
||||||
tmpname := filepath.Join("/tmp", filen)
|
for _, p := range patches {
|
||||||
log.Info("saving as", tmpname, p.Filename)
|
_, filen := filepath.Split(p.Filename)
|
||||||
raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
tmpname := filepath.Join("/tmp", filen)
|
||||||
raw.Write(p.Data)
|
log.Info("saving as", tmpname, p.Filename)
|
||||||
raw.Close()
|
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.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()
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue