more stuff

This commit is contained in:
Jeff Carr 2025-09-05 01:24:20 -05:00
parent c5025d25b2
commit 04028e6181
4 changed files with 76 additions and 54 deletions

View File

@ -87,10 +87,12 @@ func doClean() error {
}
log.Printf("\n") // padding for now
if found.Len() == 0 {
log.Printf("%d repos are not clean\n", found.Len())
var hmm int
hmm = found.Len()
if hmm == 0 {
log.Printf("%d repos are not clean\n", hmm)
} else {
log.Info("All repos are clean", total, found.Len())
log.Info("All repos are clean", total, hmm)
}
return nil
}

View File

@ -196,6 +196,10 @@ func drawWindow(win *gadgets.GenericWindow) {
all := me.forge.Patchsets.All()
for all.Scan() {
pset := all.Next()
if pset.State == "DONE" {
// skip old patchsets
continue
}
AddAllPatches(notdone, pset, false)
// AddNotDonePatches(notdone, pset, false)
}

View File

@ -115,7 +115,6 @@ func cleanSubject(line string) string {
// jcarr@framebook:~/go/src/go.wit.com/lib/protobuf/forgepb$ git merge-base --is-ancestor "4a27e7702b9b975b066ec9d2ee7ac932d86552e3" "jcarr" ; echo $?
// 0
func findCommitByHash(hash string, subject string) (string, error) {
cmd := exec.Command("git", "log", "--pretty=format:%H %s")
var out bytes.Buffer

View File

@ -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
}