window with only unapplied patches

This commit is contained in:
Jeff Carr 2025-03-23 09:30:34 -05:00
parent edc362f4b9
commit aed4c92713
2 changed files with 67 additions and 46 deletions

View File

@ -193,19 +193,6 @@ func drawWindow(win *gadgets.GenericWindow) {
releaseWin = makeModeMasterWin()
})
/*
// the Devel / Patch mode window
var patchWin *patchesWindow
gridM.NewButton("Patch Window", func() {
if patchWin != nil {
patchWin.Toggle()
return
}
patchWin = new(patchesWindow)
patchWin.initWindow()
patchWin.Show()
})
*/
var patches *stdPatchsetTableWin
gridM.NewButton("Patch Window", func() {
if patches != nil {
@ -234,6 +221,33 @@ func drawWindow(win *gadgets.GenericWindow) {
reposWin = makeReposWin()
})
var patchesWin *stdPatchTableWin
gridM.NewButton("Pending patches", func() {
if patchesWin != nil {
patchesWin.Toggle()
return
}
loadUpstreamPatchsets()
if me.psets == nil {
log.Info("failed to download current patchsets")
return
}
notdone := new(forgepb.Patches)
all := me.psets.All()
for all.Scan() {
pset := all.Next()
AddNotDonePatches(notdone, pset)
}
for patch := range notdone.IterAll() {
comment := cleanSubject(patch.Comment)
log.Info("new patch:", patch.NewHash, "commithash:", patch.CommitHash, patch.RepoNamespace, comment)
}
// savePatchsets()
patchesWin = makePatchesWin(notdone)
})
// set the initial button state based on the last
// forge mode the user saved in the config file
switch me.forge.Config.Mode {

View File

@ -36,6 +36,37 @@ func (w *stdPatchsetTableWin) Toggle() {
w.win.Toggle()
}
func loadUpstreamPatchsets() {
psets, err := me.forge.GetPatchesets()
if err != nil {
log.Info("Get Patchsets failed", err)
return
}
var foundnew bool
all := psets.All()
for all.Scan() {
pset := all.Next()
found := me.psets.FindByUuid(pset.Uuid)
if found == nil {
log.Info("new patchset", pset.Name, pset.Uuid)
pset.State = "new"
foundnew = true
} else {
log.Info("patchset already on disk", found.Name, found.State)
pset.State = found.State
if pset.State == "" {
pset.State = "new"
}
}
}
if foundnew {
log.Info("should save these here")
me.psets = psets
savePatchsets()
}
}
func makePatchsetsWin() *stdPatchsetTableWin {
dwin := new(stdPatchsetTableWin)
dwin.win = gadgets.NewGenericWindow("forge current patchsets", "patchset options")
@ -54,35 +85,8 @@ func makePatchsetsWin() *stdPatchsetTableWin {
})
grid.NewButton("upstream", func() {
psets, err := me.forge.GetPatchesets()
if err != nil {
log.Info("Get Patchsets failed", err)
return
}
var foundnew bool
all := psets.All()
for all.Scan() {
pset := all.Next()
found := me.psets.FindByUuid(pset.Uuid)
if found == nil {
log.Info("new patchset", pset.Name, pset.Uuid)
pset.State = "new"
foundnew = true
} else {
log.Info("patchset already on disk", found.Name, found.State)
pset.State = found.State
if pset.State == "" {
pset.State = "new"
}
}
}
dwin.doPatchsetsTable(psets)
if foundnew {
log.Info("should save these here")
me.psets = psets
savePatchsets()
}
loadUpstreamPatchsets()
dwin.doPatchsetsTable(me.psets)
})
grid.NewButton("save", func() {
@ -354,7 +358,12 @@ func setNewCommitHash(p *forgepb.Patchset) bool {
func AddNotDonePatches(notdone *forgepb.Patches, pset *forgepb.Patchset) {
for patch := range pset.Patches.IterAll() {
// parts := strings.Fields(patch.Comment)
comment := cleanSubject(patch.Comment)
if found := notdone.FindByCommitHash(patch.CommitHash); found != nil {
log.Info("duplicate notdone patch:", patch.NewHash, "commithash:", patch.CommitHash, patch.RepoNamespace, comment)
continue
}
repo := me.forge.FindByGoPath(patch.RepoNamespace)
if repo == nil {
@ -363,8 +372,6 @@ func AddNotDonePatches(notdone *forgepb.Patches, pset *forgepb.Patchset) {
continue
}
comment := cleanSubject(patch.Comment)
if patch.NewHash != "na" {
log.Info("already applied patch: newhash:", patch.NewHash, "commithash:", patch.CommitHash, patch.RepoNamespace, comment)
continue
@ -379,6 +386,6 @@ func AddNotDonePatches(notdone *forgepb.Patches, pset *forgepb.Patchset) {
// this patch has not been applied yet
log.Info("patch: not found hash:", patch.CommitHash, patch.RepoNamespace, comment, newhash, err)
notdone.Append(patch)
notdone.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice
}
}